well... it would be easy to do if you just wanted to rotate an object to a given angle slowly. But you want an angle to point towards a point.
Heres the function i use. If you want to understand the math in the, search "Vectors don't bite" on the forums. Otherwise, just use it
.
Basically, x and y is the position of your object. x2 and y2 is the position you want your object to point towards, angle is the angle of your object, and anglespeed is how fast you want your object to turn.
function get_deltatheta(x,y,x2,y2,angle as float, anglespeed as float)
angle=wrapvalue(angle)
null=make vector2(1)
null=make vector2(2)
null=make vector2(3)
null=make vector2(4)
set vector2 1,x,y
set vector2 2,x2,y2
subtract vector2 1,2,1
normalize vector2 1,1
set vector2 3,1,0
set vector2 4,0,-1
theta#=dot product vector2(1,3)
theta2#=dot product vector2(1,4)
theta#=acos(theta#)
theta2#=acos(theta2#)
if theta2#<90
theta#=360-theta#
endif
deltatheta#=wrapvalue(theta#-angle)
if deltatheta#<180
deltatheta#=deltatheta#
else
deltatheta#=deltatheta#-360
endif
if deltatheta#>0
deltatheta#=(deltatheta#/180)*anglespeed
else
deltatheta#=(deltatheta#/180)*anglespeed
endif
endfunction deltatheta#
Y values are interchangeable with Z values, so don't worry about that.
An example using this code would be...
yrotate object 1, object angle y(1)+get_deltatheta(object position x(1), object position z(1), object position x(target), object position z(target), object angle y(1), 30)
If you repeated that ccode over a loop, object 1 would point towards object target. The returnvalue from the function isn't what angle the object needs to be at, but how uch the object needs to turn.