If your specific coordinate is "static", that is, it doesn't move, then dark coder's example is going to be your best bet.
It gets a bit more tricky if you want your point to be able to move around, however. Like, for example, if you want monsters that chase a player through 3D space. In that case, you have to get the angle differences of your two points in 3D space, and then use trig to move your object towards its target.
For 3D space, you'll have 2 angles that are required to point in the direction of your movement vector - The Y angle (which is your rotation in the XZ plane) and the X angle (rotation in the YZ plane). Use the
atanfull() function to get these angles, like such:
yAng# = atanfull((x position of moving object) - (x position of target), (z position of moving object) - (z position of target))
xAng# = atanfull((y position of moving object) - (y position of target), (2D distance between points on XZ plane))
where the 2D distance between points on the XZ plane is found using your standard distance formula.
Once you have these angles, it's a simple matter of using your SIN() and COS() functions to find the new position of your object. Again, it's a bit more tricky in 3D because you have two angles to worry about, instead of just one, but it's pretty easily solved:
* Increment objectX# by
sin(yAng#)*cos(xAng#)*movementSpeed#
* Decrement objectY# by
sin(xAng#)*movementSpeed#
* Increment objectZ# by
cos(yAng#)*cos(xAng#)*movementSpeed#
And here's a quick example I put together for this. Use mouselook and click to move the camera, and press Space to reposition the objects. The sphere in this example acts as your moving object while the cube acts as the target point.
// Screen settings
sync on : sync rate 60
autocam off
// Randomly position two objects
make object sphere 1, 10
position object 1, rnd(300)-rnd(300), rnd(300)-rnd(300), rnd(300)-rnd(300)
make object cube 2, 10
position object 2, rnd(300)-rnd(300), rnd(300)-rnd(300), rnd(300)-rnd(300)
// Initial camera position at sphere
position camera object position x(1), object position y(1)+10, object position z(1)-50
point camera object position x(1), object position y(1), object position z(1)
// Main loop
repeat
MoveSphere()
UpdateCamera()
sync
until (escapekey() = 1)
end
// Move the sphere towards the cube
function MoveSphere()
// Get the current coordinates of the sphere (moving object) and the cube (target)
objX# = object position x(1)
objY# = object position y(1)
objZ# = object position z(1)
targetX# = object position x(2)
targetY# = object position y(2)
targetZ# = object position z(2)
// Get angle between sphere (moving object) and cube (target)
yAng# = atanfull(targetX#-objX#, targetZ#-objZ#)
d# = sqrt((targetX#-objX#)*(targetX#-objX#) + (targetZ#-objZ#)*(targetZ#-objZ#))
xAng# = atanfull(objY#-targetY#, d#)
// Move the sphere towards the target
speed# = 0.5
inc objX#, sin(yAng#)*cos(xAng#)*speed#
dec objY#, sin(xAng#)*speed#
inc objZ#, cos(yAng#)*cos(xAng#)*speed#
// Position the sphere object
position object 1, objX#, objY#, objZ#
// Reposition objects when SPACE is pressed
if spacekey() = 1 and keySp = 0
position object 1, rnd(300)-rnd(300), rnd(300)-rnd(300), rnd(300)-rnd(300)
position object 2, rnd(300)-rnd(300), rnd(300)-rnd(300), rnd(300)-rnd(300)
position camera object position x(1), object position y(1)+10, object position z(1)-50
point camera object position x(1), object position y(1), object position z(1)
endif
keySp = spacekey()
endfunction
// Basic mouselook movement
function UpdateCamera()
// Move with left and right mouse buttons
moveZ = (mouseclick()=1) - (mouseclick()=2)
// Mouse point
yAng# = wrapvalue(camera angle y() + mousemovex()*0.1)
xAng# = wrapvalue(camera angle x() + mousemovey()*0.1)
// Keep X angle in check (Don't allow player to look too far up or down)
if xAng# > 90.0 and xAng# < 180.0 then xAng# = 90.0
if xAng# < 270.0 and xAng# > 180.0 then xAng# = 270.0
// Move camera
speed# = 2.0
camX# = camera position x() + sin(yAng#)*cos(xAng#)*speed#*moveZ
camY# = camera position y() - sin(xAng#)*speed#*moveZ
camZ# = camera position z() + cos(yAng#)*cos(xAng#)*speed#*moveZ
// Position camera
position camera camX#, camY#, camZ#
rotate camera xAng#, yAng#, 0.0
endfunction
Although again, this is just if you want your "target point" to move - If it's static, then go with simple interpolation.