Frictional Games Forum (read-only)
[SOLVED] How to know if player is in jumping or falling state? - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: SOMA (https://www.frictionalgames.com/forum/forum-55.html)
+--- Forum: User created content (https://www.frictionalgames.com/forum/forum-79.html)
+---- Forum: Technical Support (https://www.frictionalgames.com/forum/forum-80.html)
+---- Thread: [SOLVED] How to know if player is in jumping or falling state? (/thread-53521.html)



[SOLVED] How to know if player is in jumping or falling state? - Mafiyia - 01-26-2017

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.


RE: How to know if player is in jumping or falling state? - Abion47 - 01-26-2017

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.


RE: How to know if player is in jumping or falling state? - Mafiyia - 01-26-2017

This is exactly what I was looking for. Thanks!