|
FAQ
• Search • Login
|
|
Page 1 of 1
|
[ 5 posts ] |
|
Author |
Message |
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
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 |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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 |
|
|
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
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 |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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 |
|
|
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
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 |
|
|
|
|
Page 1 of 1
|
[ 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
|
|