I only saw your message as I was about to put up this one. I have found a way of doing it for several stuff but only using the same equaton
Rem ++++++++++++++++++++++++++++++++++++++++++++
Rem +++++++++ Star Wars - Hoth wars ++++++++++++
Rem ++++++++++++++++++++++++++++++++++++++++++++
rem Initialisation
sync on
sync rate 30
hide mouse
autocam off
Rem star wars theme tune
load music "starwars.mid",1
play music 1
loop music 1
rem Make a terrain to fly over
make matrix 1,10000,10000,50,50
rem texture matrix
load image "grass10.bmp",2
Prepare matrix texture 1,2,2,2
rem skysphere
make object sphere 2,10000
load image "test1.bmp",4
set object 2,1,0,0
Texture object 2,4
rem tie fighter
load object "tie fighter.x",1
position object 1,100,100,400
rem background texture
texture backdrop 4
REm load the bullet
Make object sphere 3,3
color object 3,RGB(20,100,40)
rem Set up initial positions and angles
x#=5000
y#=200
z#=5000
theta#=0
phi#=0
thruststep#=0.1
Rem cockpit for ship
rem Set the ink to white and paper color to black
ink rgb(244,214,210),1
rem Load a bitmap on to the screen
load bitmap "tie3.bmp",1
rem Use this command to set drawing to the screen
set current bitmap 1
rem Grab image 1 from bitmap
get image 1,0,0,640,480,2
rem Now we will make the sprite
sprite 1,0,0,1
do
rem Mouseclicks control speed
`if mouseclick()=1 then thrust#=thrust#+thruststep#
`if mouseclick()=2 then thrust#=thrust#-thruststep#
rem Now the joystick button controls speed
if joystick fire b()=1 then thrust#=thrust#+thruststep#
rem Mouse movements control angles
`theta#=wrapvalue(theta#+mousemovex())
`phi#=wrapvalue(phi#+mousemovey())
rem Joystick controls angles
rem Change the value (currently 0.005) to set sensitivity
theta#=wrapvalue(theta#+(joystick x()*0.005))
phi#=wrapvalue(phi#-(joystick y()*0.005))
rem Decay the thrust so you don't go really fast
thrust#=thrust#*0.9
xaxisstrafe#=xaxisstrafe#*0.9
yaxisstrafe#=yaxisstrafe#*0.9
rem Accelerate the velocities (this took ages to work out)
xvel#=xvel#+(sin(theta#)*cos(phi#)*thrust#)
yvel#=yvel#-(sin(phi#)*thrust#)
zvel#=zvel#+(cos(theta#)*cos(phi#)*thrust#)
xvel#=xvel#+(sin(theta#+90)*xaxisstrafe#)
zvel#=zvel#+(cos(theta#+90)*xaxisstrafe#)
xvel#=xvel#+(sin(theta#)*cos(phi#+90)*yaxisstrafe#)
yvel#=yvel#-(sin(phi#+90)*yaxisstrafe#)
zvel#=zvel#+(cos(theta#)*cos(phi#+90)*yaxisstrafe#)
rem Some friction to stop you going too fast
xvel#=xvel#*0.99
yvel#=yvel#*0.99
zvel#=zvel#*0.99
rem Simple velocity
x#=x#+xvel#
y#=y#+yvel#
z#=z#+zvel#
rem Rotate and position the camera
position camera x#,y#,z#
yrotate camera theta#
xrotate camera phi#
Rem shoot bullet
if joystick fire a()=1 and BulletLife=0
Position object 3,x#,y#,z#
Set object to camera orientation 3
BulletLife =25
Show object 3
Endif
Rem where the bullet moves
if BulletLife > 0
Dec BulletLife
Move object 3,80
if BulletLife = 0 then Hide object 3
Endif
Rem this is for the shooting
rem object positions for the shooting
obj1x# = object position x(1)
obj1y# = object position y(1)
obj1z# = object position z(1)
obj3x# = object position x(3)
obj3y# = object position y(3)
obj3z# = object position z(3)
rem distance form bullet and the target
dist# = getdist(obj1x#,obj3x#,obj1y#,obj3y#,obj1z#,obj3z#)
rem kill the enemy when bullet is close
if dist#<100 then Hide object 1
rem distance from camera and target
camdist# = getdist(obj1x#,x#,obj1y#,y#,obj1z#,z#)
rem enemy moves if you are close
if camdist#<1000 then move object 1,20
sync
loop
function getdist(obj1x#,obj2x#,obj1y#,obj2y#,obj1z#,obj2z#)
distance# = SQRT((obj1x#-obj2x#)^2+(obj1y#-obj2y#)^2+(obj1z#-obj2z#)^2)
endfunction distance#
This means that I can check if the project is close to the enemy to kill the enemy and I can see I am close to it so that it can run away, or (with some adaption) towards you.
Thanks for your help asgood and I hope that darkjedi07 finds both of our solutions helpful.