Detecting strafing and running back ?
Moderator: InsideQC Admins
5 posts
• Page 1 of 1
Detecting strafing and running back ?
Okay, I am doing some tests with a multipart player model (pretty much the same way Q3A does - head, torso, legs). To correctly animate the legs, I need to reliably detect when the player is strafing (and if it's strafing to the left or to the right as well) and also if is running back. Problem is, I suck badly at this vector math mumbo-jumbo
. Help ? 
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
There are actually two ways of doing this: By pointing the legs to the direction the player is moving, or by pointing them to the direction he's trying to move.
In the first case, if you try to walk sideways and a wall blocks you, your legs won't turn to the side, because you've stopped. In the second case, your legs will keep facing the direction you wanted to go.
Coding the first case in QC is simple, since all you need is the velocity and angles, but coding the second case is harder and may require access to the raw input of the keyboard/mouse/controller.
In the first case, if you try to walk sideways and a wall blocks you, your legs won't turn to the side, because you've stopped. In the second case, your legs will keep facing the direction you wanted to go.
Coding the first case in QC is simple, since all you need is the velocity and angles, but coding the second case is harder and may require access to the raw input of the keyboard/mouse/controller.
-

mankrip - Posts: 915
- Joined: Fri Jul 04, 2008 3:02 am
record the velocity in postthink
read it in prethink
any changes are due to either:
missile impacts/damage/teleporters
or
player's desired motion.
this is true even if they're running into a wall.
to rotate a velocity into a vector which is expressed relative to an angle instead of world space:
movement_x = velocity*v_forward;
movement_y = velocity*v_right;
movement_z = velocity*v_up;
(vector * vector is a dotproduct in QC)
note that if you're using the change from postthink to prethink, you need to use the delta, rather than the actual velocity, or the direction of movement will appear to 'slowly' rotate as they switch strafe direction (for perfect results, you can clear out the velocity in postthink, but that will affect physics).
Of course, if you're using DP or FTE, you can just read .movement in PlayerPreThink to see the directions the player wants to move in (relative to their angles rather than world). Which is much much simpler.
It depends if you want to use the values they wanted *this frame* or if you want it relative to the current velocity, really. If you want it based upon their current velocity (which include rocket impacts and slow turning) then you would still need the above dotproducts.
read it in prethink
any changes are due to either:
missile impacts/damage/teleporters
or
player's desired motion.
this is true even if they're running into a wall.
to rotate a velocity into a vector which is expressed relative to an angle instead of world space:
movement_x = velocity*v_forward;
movement_y = velocity*v_right;
movement_z = velocity*v_up;
(vector * vector is a dotproduct in QC)
note that if you're using the change from postthink to prethink, you need to use the delta, rather than the actual velocity, or the direction of movement will appear to 'slowly' rotate as they switch strafe direction (for perfect results, you can clear out the velocity in postthink, but that will affect physics).
Of course, if you're using DP or FTE, you can just read .movement in PlayerPreThink to see the directions the player wants to move in (relative to their angles rather than world). Which is much much simpler.
It depends if you want to use the values they wanted *this frame* or if you want it relative to the current velocity, really. If you want it based upon their current velocity (which include rocket impacts and slow turning) then you would still need the above dotproducts.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Spike wrote:Of course, if you're using DP or FTE, you can just read .movement in PlayerPreThink to see the directions the player wants to move in (relative to their angles rather than world). Which is much much simpler.
^^^ This. I'm using DP, will check it. Thanks for the help guys!
EDIT: Yup, works like a charm. Thanks again!
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest