moving one object from one point in space to another is better to be independent from object rotation or local direction and must reach its distance with 100% accuracy.
here is a simple code where moving an object is relying on time/speed values.
sync on : sync rate 60
#constant _3Dvector = 1
#constant _floor 1
#constant _box 2
#constant _sphere 3
#constant _framerate 60 `will help in not creating quick jumpings for small distances.
`suggest a speed
#constant _speed 4.5
`set your camera
autocam off
position camera 0,10,-20
point camera 0,0,0
`create environment
makeobjectbox(_floor,50,1,50,0,0,0,0xFF003300)
makeobjectbox(_box,2,2,2,0,2,0,0xFFAA0000)
makeobjectsphere(_sphere,2,10,5,20,0xff00AAAA) : ghost object on _sphere,2
r = make vector3(_3Dvector)
`create vector 3D only to calculate the distance between both objects
Xdistance# = object position x(_sphere)-object position x(_box)
Ydistance# = object position y(_sphere)-object position y(_box)
Zdistance# = object position z(_sphere)-object position z(_box)
set vector3 _3Dvector,Xdistance#,Ydistance#,Zdistance#
distance# = length vector3(_3Dvector)
`how long will it take for the box to reach the sphere.
time# = distance# / _speed
`how many steps we need to move the box to the middle of the sphere.
numberofsteps = ceil(time#*_framerate)
`now lets evaluate steps on each axis
steponx# = Xdistance# / numberofsteps
stepony# = Ydistance# / numberofsteps
steponz# = Zdistance# / numberofsteps
do
set cursor 2,2
print "press space key to start moving the red box into the middle of the sphere"
if spacekey()
position object _box,0,2,0
repeat until not spacekey()
moveobject(_box, steponx#, stepony#, steponz#, numberofsteps)
endif
turn object left _box,3
control camera using arrowkeys 0,1,1
sync
LOOP
wait key
end
function moveobject(objno, xstep#, ystep#, zstep#, numberofsteps)
stepped = 0
repeat
turn object left objno,3
position object objno, object position x(objno)+xstep#, object position y(objno)+ystep#, object position z(objno)+zstep#
inc stepped,1
sync
UNTIL stepped = numberofsteps
ENDFUNCTION
function makeobjectbox(objno,width#,height#,depth#,posx#,posy#,posz#,color)
make object box objno,width#,height#,depth#
position object objno,posx#,posy#,posz#
color object objno,color
ENDFUNCTION
function makeobjectsphere(objno,size#,posx#,posy#,posz#,color)
make object sphere objno,10
position object objno,posx#,posy#,posz#
color object objno,color
ENDFUNCTION
