Atan2 problem

BlitzMax Forums/BlitzMax Programming/Atan2 problem

Robert Cummings(Posted 2005) [#1]
Hi,

I have up to 200 enemies who need to rotate to point in the direction they are travelling.

This game is targetted to run on a P2-450 and above, therefore would Atan2 be very expensive?

Are there alternatives to finding the rotation based on 2 coordinates, or failing that, I am able to provide a movement vector vx,vy.


Chroma(Posted 2005) [#2]
You could just normalize the 2d movement vector then rotate the object accordingly. I believe you can use sin and cosine on the normalized component to find the angle.


Chroma(Posted 2005) [#3]
Ok here's something that might help. You store the x and y speeds in the vector and normalize to find the direction vector. Hope it helps.




Robert Cummings(Posted 2005) [#4]
Very helpful, thanks :)


And quite clever...


FlameDuck(Posted 2005) [#5]
This game is targetted to run on a P2-450 and above, therefore would Atan2 be very expensive?
Nope.