Frictional Games Forum (read-only)

Full Version: [SOLVED] How to know if player is in jumping or falling state?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a method that can tell me if the player is in the jumping state? I know there is a Player_Jump() method that makes the player jump, but I'm looking for a method that returns true if the player is jumping and false if not or something that resembles that.
There is no pre-built IsPlayerJumping or IsPlayerFalling function that I'm aware of, but there are a couple ways to get the same effect.

First, you could check the player's character body's velocity. If the vertical velocity is greater than zero, then they are ascending (jumping) and if it's less than zero, then they are descending (falling):

Code:
cVector3f velocity = cLux_GetPlayer().GetCharacterBody().GetForceVelocity();
bool isJumping = (velocity.y != 0);

Second, you can check if the character body's feet are on the ground. If not, then they are in the air as a result of either jumping or falling:

Code:
bool isJumping = !(cLux_GetPlayer().GetCharacterBody().IsOnGround());

The first method can throw false positives if the player is ascending or descending for other reasons (such as climbing a ladder or walking down stairs) and the second method doesn't tell you whether the player is rising or falling on its own, so you can get all the information if you combine the two.
This is exactly what I was looking for. Thanks!