Page 1 of 1
Angles, Directions, Trig...
Posted: 21 Mar 2012, 15:39
by aGorm
Hi guys, working on a script for a unit and running into a whole load of mindslopionation re what the games returning angle wise.
Code: Select all
unitdir1,unitdir2,unitdir3 = Spring.GetUnitDirection(unitID)
in this case am I right in thinking that unitdir1 will be which way the unit is facing? In which case where's that measured from (IE is that from "north" "south" "east" or "west"). Also am I right in thinking this is returning (stupidly) values from -pi to pi? (Instead of 0 to 2pi which is what I expected... I take it theres a reason...)
Thanks
aGorm
Re: Angles, Directions, Trig...
Posted: 21 Mar 2012, 19:23
by zwzsg
I would say unitdir1, unitdir2, unitdir3 are the cartesian coordinates (that, is, the X, the Y, the Z) of a vertex. This vertex direction is the same as the unit direction.
So no, they are not angles in the [-pi,pi] range. They are coordinates in the [-1,1] range (assuming the vertex is normalised).
Mostly a guess, though.
Re: Angles, Directions, Trig...
Posted: 21 Mar 2012, 21:13
by FLOZi
zwzsg wrote:I would say unitdir1, unitdir2, unitdir3 are the cartesian coordinates (that, is, the X, the Y, the Z) of a vertex. This vertex direction is the same as the unit direction.
So no, they are not angles in the [-pi,pi] range. They are coordinates in the [-1,1] range (assuming the vertex is normalised).
Mostly a guess, though.
Would be my guess / recollection also.
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 10:49
by aGorm
Ok, you've both really lost me there? Are you saying that they are the coordinates of a point which a line from the unit center would travel though that is pointing in the direction the unit is facing?
IE, if unitdir1=1 and the others are all 0 the unit is facing towards X?
And if unitdir1=0.5 then either unitdir2 or 3 would be 0.866...ish?
If so thats fine I can work with that, it's just a pain in the arse and I can't imagin why anyone would need those values in that format...
(I assume there is some cool math that you can do with it though and someone who's good at math will prob look at my script and go why the hell is he doing everything like this?)
aGorm
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 13:39
by Google_Frog
It's just a vector, they are quite useful.
If you want x,z direction use this:
Code: Select all
dir = Spring.GetUnitHeading(unitID)/32768*math.pi
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 13:56
by aGorm
Thanks... out of intrest whats the /32768 for? Just some magic constant?
aGorm
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 14:13
by Google_Frog
32768 = 2^15
There are 2^16 heading units in a circle and 2pi radians in a circle.
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 14:24
by aGorm
That explains why when I tryed it with heading everything went weird... I assumed it returned in radians.
aGorm
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 14:52
by Senna
aGorm wrote:Thanks... out of intrest whats the /32768 for? Just some magic constant?
aGorm
32768 binary number
Re: Angles, Directions, Trig...
Posted: 22 Mar 2012, 15:22
by aGorm
Woohahahha it works. After a lot of head banging I have 3 legs positioned with the power of math! It's strange how you forget how trig works when you havn't done it for 10 years...
not that this pic explains much but the legs are positioned by the numbers echoing at the top, which are worked out from 3 empty peices in the root of the object and then ofset by the unit rotation. (by default all the legs are just pointing stright back...)
This means I can now feed in cordinates of where the leg was previously and move it to there, and thus create the illusion of the feet sticking to the ground... well after I get the legs to also extend out to the points aswell... more math...
aGorm