Data Realms Fan Forums
http://45.55.195.193/

Aim angle to vector
http://45.55.195.193/viewtopic.php?f=73&t=14706
Page 1 of 1

Author:  Darlos9D [ Sun May 17, 2009 3:39 am ]
Post subject:  Aim angle to vector

So, I've been thinking deeply about how to accomplish some targeting and stealth elements, and realized that it'd be handy if I knew how to go about turning an actor's aim angle into a vector that could be used for ray casting.

Thing is, CC seems to handle the aim angle kinda oddly. If you do Actor:GetAimAngle(true), you get back a value in radians that's adjusted to consider whether the character is facing left or right. The resulting values are set up like this, if we speak in terms of Cartesian quadrants:

Quadrant 1: goes from 0 radians (directly right) to pi/2 radians (directly up)
Quadrant 2: goes from pi/2 radians (directly up) to pi radians (directly left)
Quadrant 3: goes from pi radians (directly let) to pi*(3/2) radians (directly down)

Normal so far, right? Well...

Quadrant 4: goes from 0 radians (directly right) to NEGATIVE pi/2 radians (directly down)

So basically, everything is normal except for the 4th quadrant. Of course, it's laid out as one would expect if it were to be negative, so it's not really TOO huge of a deal.

Now I'm gonna go bang my head against some trigonometry to see if I can pull a nice vector out of a given value... which should be possible, it's just that the solution doesn't immediately strike me. If anybody else is a bit more mathematically savvy than me, go ahead and respond with a solution.

EDIT: Nevermind, figured it out in one trip to Google:

X = Math.Cos(angle);
Y = Math.Sin(angle);

Author:  TheLastBanana [ Sun May 17, 2009 3:58 am ]
Post subject:  Re: Aim angle to vector

Just invert the radians and then run math.deg() on it, and they're perfectly normal degrees as far as I know.

Author:  Darlos9D [ Sun May 17, 2009 4:07 am ]
Post subject:  Re: Aim angle to vector

TheLastBanana wrote:
Just invert the radians and then run math.deg() on it, and they're perfectly normal degrees as far as I know.

Actually, I didn't even have to do that. math.sin and math.cos can both handle the negatives perfectly.

Now, here's an important question: how do I go about declaring a brand new vector for me to use?

Author:  Geti [ Sun May 17, 2009 4:08 am ]
Post subject:  Re: Aim angle to vector

i've just told roon the same thing about 9 hours ago.
Code:
whatever = Vector(X,Y)
where whatever is your vector.
you can also call whatever.X and whatever.Y after declaring whatever.

Author:  Darlos9D [ Sun May 17, 2009 4:09 am ]
Post subject:  Re: Aim angle to vector

Geti wrote:
i've just told roon the same thing about 9 hours ago.
Code:
whatever = Vector(X,Y)
where whatever is your vector.
you can also call whatever.X and whatever.Y after declaring whatever.

Ah, thanks. I knew the second part already though.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/