This code makes a sprite move towards a target.
box 0,0,16,16,rgb(0,255,0)
box 1,1,15,15,rgb(0,100,0)
box 4,15,12,32,rgb(0,255,25)
box 5,14,11,31,rgb(0,100,0)
get image 1,0,0,16,32,1
box 0,0,8,8,rgb(255,255,255)
box 1,1,7,7,rgb(255,0,0)
get image 2,0,0,8,8
sprite 1,screen width()/2,screen height()/2,1
sprite 2,rnd(screen width()),rnd(screen height()),2
offset sprite 1,8,16
offset sprite 2,4,4
do
x1# = sprite x(1)
y1# = sprite y(1)
x2# = sprite x(2)
y2# = sprite y(2)
nDistance = sqrt((x1#-x2#)^2 + (y1#-y2#)^2)
while nDistance > .5
x1# = sprite x(1)
y1# = sprite y(1)
x2# = sprite x(2)
y2# = sprite y(2)
` I'm seriously math deficient, but this works
angle#=ATAN((y1#-y2#)/(x1#-x2#))
if x2# <= x1# then angle#=angle#-90.0 else angle# = angle#+90.0
rotate sprite 1,angle#
move sprite 1,.05
nDistance = sqrt((x1#-x2#)^2 + (y1#-y2#)^2)
endwhile
sprite 2,rnd(screen width()),rnd(screen height()),2
loop
I'm sure the more mathematically inclined could give you a better formula.