![]() |
|
Angle Vectoring |
Don Freeman
Member #5,110
October 2004
![]() |
Ok...I'd first like to say hello again to everyone Here's my question: typedef struct _Object I've looked at a couple of math equations, but I may be doing something wrong or I am just totally confused. To find the vector: I think you use the DOT Product to find the angle, but when I try it...it doesn't seem to work for me: The goal is to find the angle from (player.x, player.y) to (target.x, target.y) so I can determine where to turn left / right or keep on current angle to reach target. Thanks in advance. -- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Here's some console prog stuff to demonstrate radians to polar coords and vice versa
gcc math lib is probably necessary, -lm. They all watch too much MSNBC... they get ideas. |
Don Freeman
Member #5,110
October 2004
![]() |
Thanks! I knew I was missing something...but I couldn't think of what it was! Had to convert radians to polar coords...just didn't know how! Thanks again! Now...where did I leave off with this program....::) -- |
Krzysztof Kluczek
Member #4,191
January 2004
![]() |
atan2 ________ |
Niunio
Member #1,975
March 2002
![]() |
Or use dot product. Amarillion has a great tutorial about sin, cos and all that stuff. It should be at pixwiki, but now bafsoft server seems down so I can't find it. Anyway, I have a copy of most of pixelate tuts so I've attached the tutorial, wich includes both atan2 and dot product examples. ----------------- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
atan2, huh! I don't remember why I did the above code (years ago), maybe it was so I could do it in asm as well, or maybe my compiler didn't have an atan2 then. I thought it wasn't supported by all compilers but dj info says it's ANSI. Learn something new every day. They all watch too much MSNBC... they get ideas. |
Andrei Ellman
Member #3,434
April 2003
|
The dot product is overkill for 2 dimensions. I'd use atan2. AE. -- |
|