Hello z_man. You can do that if you find out the distance between both objects...
have a look in this example.
greetings
hide mouse
autocam off
sync on
rem we create the texture for matrix
create bitmap 3,50,50
for i= 1 to 3000
ink rgb(rnd(50),rnd(130),rnd(50)),1
line rnd(60),rnd(60),rnd(60),rnd(60)
next i
blur bitmap 3,3
get image 6,0,0,50,50
delete bitmap 3
rem we make the matrix
make matrix 1,10000.0,10000.0,4,4
prepare matrix texture 1,6,1,6
rem we make both object player and enemy object
make object box 1,20,90,20
make object box 2,20,90,20
pos_dumy2_x#=600
pos_dumy2_z#=800
position object 2,pos_dumy2_x#,0,pos_dumy2_z#
rem starting positions
`posision_dumy_x posision_dumy_z
pos_dumy_x#=500
pos_dumy_z#=500
position object 1,pos_dumy_x#,0,pos_dumy_z#
position camera pos_dumy_x#-120,100,pos_dumy_z#-120
rem the camera points starting position of player
point camera pos_dumy_x#,1,pos_dumy_z#
do
gosub _controla_dumy
gosub _controla_dumy2
sync
loop
_controla_dumy:
rem left and right rotations
if leftkey()=1 then gira#=wrapvalue(gira#-2)
if rightkey()=1 then gira#=wrapvalue(gira#+2)
rem player movings
if upkey()=1 THEN pos_dumy_x#=NEWXVALUE(pos_dumy_x#,gira#,1)
if upkey()=1 then pos_dumy_z#=NEWZVALUE(pos_dumy_z#,gira#,1)
if downkey()=1 THEN pos_dumy_x#=NEWXVALUE(pos_dumy_x#,gira#,-1)
if downkey()=1 then pos_dumy_z#=NEWZVALUE(pos_dumy_z#,gira#,-1)
rem update positions
POSITION OBJECT 1,pos_dumy_x#,0,pos_dumy_z#
yrotate object 1,gira#
return
_controla_dumy2:
rem if we are to close to enemy, we are detected by enemy and we´ll be atak
corre#=wrapvalue(corre#+20)
if distancia# <300 then point OBJECT 2,pos_dumy_x#,0,pos_dumy_z#
`we find out the distance between both objects
dx#=object position x(2)-object position x(1)
dz#=object position z(2)-object position z(1)
distancia#=sqrt((dx#*dx#)+(dz#*dz#))
angulo_objeto_2#=object angle y(2)
rem if distance is minor 200 then....
if distancia#<200
pos_dumy2_x#=NEWXVALUE(pos_dumy2_x#,angulo_objeto_2#,0.2)
pos_dumy2_z#=NEWZVALUE(pos_dumy2_z#,angulo_objeto_2#,0.2)
endif
rem update positions
POSITION OBJECT 2,pos_dumy2_x#,0,pos_dumy2_z#
yrotate object 2,angulo_objeto_2#
return
oh my god