View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:39 am



Reply to topic  [ 5 posts ] 
 Aim angle to vector 
Author Message
User avatar

Joined: Mon Jul 16, 2007 9:50 am
Posts: 1512
Location: Tallahassee, FL
Reply with quote
Post 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);


Sun May 17, 2009 3:39 am
Profile YIM
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Sun May 17, 2009 3:58 am
Profile WWW
User avatar

Joined: Mon Jul 16, 2007 9:50 am
Posts: 1512
Location: Tallahassee, FL
Reply with quote
Post 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?


Sun May 17, 2009 4:07 am
Profile YIM
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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.


Sun May 17, 2009 4:08 am
Profile WWW
User avatar

Joined: Mon Jul 16, 2007 9:50 am
Posts: 1512
Location: Tallahassee, FL
Reply with quote
Post 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.


Sun May 17, 2009 4:09 am
Profile YIM
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.080s | 13 Queries | GZIP : Off ]