Angle by x/y.. again
Moderator: Moderators
Angle by x/y.. again
Yes i know i made a post on this before and got two methods of doing it, but i'll be in the church of pkm if i could get any of it to work.
What i need is a method or algorithm to get the amount a game entity needs to rotate to be facing a given x/y coord. distance, angles, etc aren't a problem, i just cant figure out how to do it, much less efficiently.
yes this is a "make a map for me plzplzplzplz?" post. can anyone just give me a coded way to return the amount a game ent would need to rotate to face a given xy (it'll eventually end up radians but even i can convert degrees to them)?
i'm at that desperate stage where everything else kinda needs this, so...
What i need is a method or algorithm to get the amount a game entity needs to rotate to be facing a given x/y coord. distance, angles, etc aren't a problem, i just cant figure out how to do it, much less efficiently.
yes this is a "make a map for me plzplzplzplz?" post. can anyone just give me a coded way to return the amount a game ent would need to rotate to face a given xy (it'll eventually end up radians but even i can convert degrees to them)?
i'm at that desperate stage where everything else kinda needs this, so...
Moderator
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
Vector
I think what you are looking for is "vector_toangles". But, I can't remember how it is used, although I think it requires two entity origins or coordinates.
myvec = vector_toangles(myent1.origin, myent2.origin)
or
myvec = vector_toangles(myent1.origin - myent2.origin)
There might be something in this post that will help.
/forum/viewtopic.php?t=10489
myvec = vector_toangles(myent1.origin, myent2.origin)
or
myvec = vector_toangles(myent1.origin - myent2.origin)
There might be something in this post that will help.
/forum/viewtopic.php?t=10489
Alright here's what i need. Imagine two soldiers on either side of a field.
Now, to shoot at each other the soldiers really should be looking at each other right? This is what i'm after. What kind of algorithm would the soldier have to determine how much he should rotate to face his enemy?
in other words, how many radians does he need to turn to face his enemy from his current angle?
Getting angles x/y and distance isn't a problem, and i know there's a way to do it, (almost every game does) but i can't figure it out.
The 'soldiers' don't use vectors either, which may have been a huge mistake on my part. But i know there must be a way to do it without vectors.
Code: Select all
|| || ^ and > indicate facing
|| o> ^ ||
|| o ||
|| ||
|| ||
in other words, how many radians does he need to turn to face his enemy from his current angle?
Getting angles x/y and distance isn't a problem, and i know there's a way to do it, (almost every game does) but i can't figure it out.
The 'soldiers' don't use vectors either, which may have been a huge mistake on my part. But i know there must be a way to do it without vectors.
Last edited by lizardkid on Sat Aug 05, 2006 1:52 am, edited 1 time in total.
Moderator
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
lookat
If a 'soldier' stops to do a math problem, he'll be dead before he can act. Can't you just use the "lookat" command?
Ok so I suppose for each soldier you have a x and a y coordinate?
Then it'll be an atan fest
If the language you're using supports it, just use atan2.
angle = atan2(y2-y1,x2-x1)
That'll give you the absolute angle in the usual mathematical convention:
Where, usually, angle ranges between [-pi,pi) or [-180,180).
Now I suppose you store a yaw angle for each soldier, then the relative angle you asked for (i.e. how much to turn), is simply
relative_angle = angle - yaw1
Note that this implies yaw1 is defined by the same convention as above.
Hope you can get it to work, let us know either way
Then it'll be an atan fest
If the language you're using supports it, just use atan2.
angle = atan2(y2-y1,x2-x1)
That'll give you the absolute angle in the usual mathematical convention:
Code: Select all
y
^
| /
| /
| /\ positive angle
|/ |
0------------>xNow I suppose you store a yaw angle for each soldier, then the relative angle you asked for (i.e. how much to turn), is simply
relative_angle = angle - yaw1
Note that this implies yaw1 is defined by the same convention as above.
Hope you can get it to work, let us know either way
It finally works!
I had to do quite a bit of tweaking and testing to get it to the stage i was happy with, but the algorithm works flawlessly in all circumstances i've tossed it throguh so far.
Can't tell you how happy i am this works, that was the major stumbling block i had before i could get on to more interesting things, like finding cover and intercepting enemies. thanks jv!
I had to do quite a bit of tweaking and testing to get it to the stage i was happy with, but the algorithm works flawlessly in all circumstances i've tossed it throguh so far.
Can't tell you how happy i am this works, that was the major stumbling block i had before i could get on to more interesting things, like finding cover and intercepting enemies. thanks jv!
Moderator
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
-
Rookie One.pl
- Site Admin
- Posts: 2752
- Joined: Fri Jan 31, 2003 7:49 pm
- Location: Nowa Wies Tworoska, Poland
- Contact:




