Angles, Directions, Trig...

Angles, Directions, Trig...

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Angles, Directions, Trig...

Post 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
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Angles, Directions, Trig...

Post 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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Angles, Directions, Trig...

Post 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.
User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: Angles, Directions, Trig...

Post 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
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Angles, Directions, Trig...

Post 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
User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: Angles, Directions, Trig...

Post by aGorm »

Thanks... out of intrest whats the /32768 for? Just some magic constant?

aGorm
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Angles, Directions, Trig...

Post by Google_Frog »

32768 = 2^15

There are 2^16 heading units in a circle and 2pi radians in a circle.
User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: Angles, Directions, Trig...

Post by aGorm »

That explains why when I tryed it with heading everything went weird... I assumed it returned in radians.

aGorm
Senna
Posts: 315
Joined: 17 Mar 2009, 00:20

Re: Angles, Directions, Trig...

Post by Senna »

aGorm wrote:Thanks... out of intrest whats the /32768 for? Just some magic constant?

aGorm
32768 binary number
User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: Angles, Directions, Trig...

Post 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...)
itworkshahaha.jpg
(89.29 KiB) Downloaded 3 times
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
Post Reply

Return to “Game Development”