Change: Disable Jumping/Sprinting while Crouching
by Glenn Bermingham · 06/13/2013 (6:14 pm) · 8 comments
If you crouched under an object and then started sprinting or jumping your player would stand up and get stuck in the object above it. This resource will simply add a simple check to see if the player is currently crouching if you try sprinting or jumping.
Be warned this will disable jumping while crouching altogether.
In Engine / source / T3D / player.cpp
Change:
and change:
Now build your Project DLL, any questions just ask below.
Be warned this will disable jumping while crouching altogether.
In Engine / source / T3D / player.cpp
Change:
bool Player::canSprint()
{
return mAllowSprinting && mState == MoveState && mDamageState == Enabled && !isMounted() && mEnergy >= mDataBlock->minSprintEnergy && !mSwimming;
}to:bool Player::canSprint()
{
return mAllowSprinting && mState == MoveState && mDamageState == Enabled && !isMounted() && mEnergy >= mDataBlock->minSprintEnergy && mPose != CrouchPose && !mSwimming;
}and change:
bool Player::canJump()
{
return mAllowJumping && mState == MoveState && mDamageState == Enabled && !isMounted() && !mJumpDelay && mEnergy >= mDataBlock->minJumpEnergy && mJumpSurfaceLastContact < JumpSkipContactsMax && !mSwimming && (mPose != SprintPose || mDataBlock->sprintCanJump);
}to:bool Player::canJump()
{
return mAllowJumping && mState == MoveState && mDamageState == Enabled && !isMounted() && !mJumpDelay && mEnergy >= mDataBlock->minJumpEnergy && mJumpSurfaceLastContact < JumpSkipContactsMax && !mSwimming && mPose != CrouchPose && (mPose != SprintPose || mDataBlock->sprintCanJump);
}Now build your Project DLL, any questions just ask below.
About the author
I spend most of my time working on games.
#2
06/13/2013 (9:25 pm)
Took me a bit to work out how to use Github but, done and done. Pull Request added.
#3
06/14/2013 (4:24 am)
Good stuff, and usefully! Thanks for share.
#4
For example you can spring while straight up and also spring while crouched.
Also for jumping you sometimes need to crouch also, in some games you can jump up a little higher edges with crouching while jumping or you can jump into a small opening while crouched that would be to small to fit the player if he would stand straight.
Bugfixing is ok but I would look for a way to keep to possibilities still in.
06/14/2013 (5:59 am)
Why disable jumping and sprinting while crouching? It is pretty common to have that in games, adds more variation and freedom of movement.For example you can spring while straight up and also spring while crouched.
Also for jumping you sometimes need to crouch also, in some games you can jump up a little higher edges with crouching while jumping or you can jump into a small opening while crouched that would be to small to fit the player if he would stand straight.
Bugfixing is ok but I would look for a way to keep to possibilities still in.
#5
06/14/2013 (9:52 am)
@Duion You could never truly jump or sprint from a crouching position. If you sprinted while crouching you'd stand up and than sprint in one motion, Torque doesn't have any code for a 3rd pose of sprinting while crouching. Same goes for Jumping, you'd just stand up hence why I added these checks in. Also jump crouching has never worked in Torque, the collision of the player remains the same size while jumping. I believe the collision is built from the ground up meaning if you changed to the crouch pose mid air the bottom of the player would still be at the same height as standing.
#6
For the sprinting thing, you have something like this in Arma2, you can change the player to crouch position and then sprint also, the crouched position is when you need more cover and when you sprint with it, you are a little slower than, if you were straight up.
06/15/2013 (4:33 am)
Ok you could make him change to standing position and then jump and then crouch again, if you try to jump while crouched.For the sprinting thing, you have something like this in Arma2, you can change the player to crouch position and then sprint also, the crouched position is when you need more cover and when you sprint with it, you are a little slower than, if you were straight up.
#7
I would work out a way to that instead. Not saying what you have here is bad, but it could be improved upon and further developed.
06/30/2013 (12:51 pm)
Duion has a point. Ever play Half-Life where you have to crouch-jump into vents?I would work out a way to that instead. Not saying what you have here is bad, but it could be improved upon and further developed.
#8
If that's the mechanic you want for your game then great, but if it's just a response to getting stuck in overhead objects there are better solutions that still allow normal player movement. E.g. a simple hack (if you don't want to fix the collision issues) would be to just cast a ray straight up from the players position and if something is too close overhead, then disable jumping/standing/etc.
Edit: Looking at the code, there's already a method to check if the player can stand, Player::canStand(); have you tried adding that to the Player::canJump() or Player::canSprint() methods?
07/08/2013 (8:50 am)
I also agree that jumping/sprinting should not be completely disabled when crouching; it's the norm to be able to do those from a crouch position. If that's the mechanic you want for your game then great, but if it's just a response to getting stuck in overhead objects there are better solutions that still allow normal player movement. E.g. a simple hack (if you don't want to fix the collision issues) would be to just cast a ray straight up from the players position and if something is too close overhead, then disable jumping/standing/etc.
Edit: Looking at the code, there's already a method to check if the player can stand, Player::canStand(); have you tried adding that to the Player::canJump() or Player::canSprint() methods?

Associate Steve Acaster
[YorkshireRifles.com]
Sort of thing which would be great as a pull request on github ...