Fighter,
To get a more precise understanding of your need, do you need object B to translate(move to a location at a moment's time) to where object A is. Or, do you want object B to 'walk' to object A, gradually making its way there? Either or, I will answer both.
To make object B translate to where object A is, simply find the coordinates of object A, via
OBJECT POSITION X(Object Number),
OBJECT POSITION Y(Object Number), and
OBJECT POSITION Z(Object Number). Then, assign these coordinates to object B, using
POSITION OBJECT Object Number,X,Y,Z.
However, to make object B 'walk' to object A is a bit trickier, though simple once learned. To do this, you first need to find the angle between the two objects with the command,
ATANFULL(Distance X, Distance Y). Replace
Distance Y with
Distance Z, to keep this consistent. Try this,
ATANFULL(obj1_x# - obj2_x#,obj1_z# - obj2_z#). Now, what is left to do is make object B(obj2) follow object A(obj_1) when the spacekey is pressed.
In the code snippet below I have used
cos and
sin maths to make object B follow object A.
obj2_x# = obj2_x# + sin(angle_y#)
obj2_z# = obj2_z# + cos(angle_y#)
Since, we are needing to make movement on two dimensions, x and z, we must use an angle value of the third dimension, in this case the y axis. Look at
figure 1. When finding movement on other dimensions, other axises' angles will be used. Look at
figure 2.
Green = Z axis : Red = X axis : Blue = Y axis
If I understood math a bit more, I would explain to you why sin and cos are used where they are. However, as I did, with a little experimentation with the two, you can learn how to bridle them and use them properly. Well, in this situation at least. Cos and sin can be made to also create ellipses movement and much more. But, one must understand the two to create the proper formulas.
Here is a code snippet with source code of a runnable program for you to use, which allows the user to press the spacebar to make object B follow object A.
set display mode 800,600,32
sync on
sync rate 60
backdrop on
color backdrop rgb(10,10,10)
set ambient light 30
REM << make object A
make object sphere 1,10
REM << make intital coordinate positions and position it with them
obj1_x# = 10
obj1_z# = 30
position object 1,obj1_x#,0,obj1_z
REM << make object B
make object sphere 2,10
REM << make initial coordinate positions and position it with them
obj2_x# = -200
obj2_z# = 0
position object 2,obj2_x#,0,obj2_z#
REM << position camera at an overview angle
position camera 50,40,40
yrotate camera 270
xrotate camera 30
REM <<<<<<<<<<<<< main program loop >>>>>>>>>>>>>>
repeat
REM << control object A with cursor keys
if rightkey() = 1 then inc obj1_z#
if leftkey() = 1 then dec obj1_z#
if upkey() = 1 then dec obj1_x#
if downkey() = 1 then inc obj1_x#
REM << make object B follow object A
if spacekey() = 1
REM << find distance in between objects, and only make object B walk if it is so far away
if sqrt((obj2_x# - obj1_x#)^2 + (obj2_z# - obj1_z#)^2) > 20
REM << find angle between the two objects for (x2-x1 + z2-z1)=y angle and (x2-x1 + y2-y1)=x angle
angle_y# = atanfull(obj1_x# - obj2_x#,obj1_z# - obj2_z#)
REM << use cos and sin math functions to make object B walk at the angle calculated
obj2_x# = obj2_x# + sin(angle_y#)
obj2_z# = obj2_z# + cos(angle_y#)
endif
endif
REM << update objects' positions
position object 1,obj1_x#,0,obj1_z#
position object 2,obj2_x#,0,obj2_z#
REM << print controls to screen
ink rgb(100,0,0),0
center text 400,555,"press arrow keys to control object A"
center text 400,570,"press spacekey to move object B to object A"
center text 400,585,"press a mouse button to end the program"
REM << print object names on each object
ink rgb(100,100,0),0
if object in screen(1) = 1 then center text object screen x(1),object screen y(1),"object A"
if object in screen(2) = 1 then center text object screen x(2),object screen y(2),"object B"
sync
until mouseclick() > 0

+NanoBrain+