setrotation() point object

BlitzMax Forums/BlitzMax Beginners Area/setrotation() point object

B(Posted 2009) [#1]
hi,

I have a problem.
Here i my code for my whole small program.

now I am trying to make it so when you are within a certain distance, the enemy points at you and then moves towards you. I am having trouble with the pointing at part.

I do not know how to do this.

EDIT:code taken out

B


Brucey(Posted 2009) [#2]
This kind of question has been asked many times on these forums :-)

The function you are interested in using, is ATan2. Put that into the search box, and you should get several very relevant posts, with useful examples.


B(Posted 2009) [#3]
thanks Brucey.

i tried searching, but I didnt know what to put in. thanks for the guidance


Yahfree(Posted 2009) [#4]
Function PointsToAngle:Float(x1:Float,y1:Float,x2:Float,y2:Float)
	Local direction#= ATan2(y1-y2,x1-x2)+180
	
	While direction > 360
		direction:-180
	Wend
	
	While direction<0
		direction:+180
	Wend
	
	Return direction

EndFunction

this will return the angle from x,y1 to x,y2.


B(Posted 2009) [#5]
thanks but i got it already by searching for Atan2

thanks anyways Yahfree