So, this is supposedly a simple question, but i’m having problems with this for about two weeks now…
What I need:
__ I just need to know when my character has reached the jump peak/apex, __ so I can run an animation at that point and perform other routines.Where I'm currently at:
I'm checking in the Update() method if the vertical velocity equals 0 and if the character is not on the ground, like this:if (Mathf.Approximately(myRB.velocity.y, 0.0f) && !isGrounded) // On Apex (not working on jump peak)
{
Debug.Log("apex");
}
isGrounded is a boolean variable that is currently working perfectly, which uses a trigger collider.
What I've already also tried:
Checking in the FixedUpdate() method, and not using Mathf.Approximately (just checking with myRB.velocity.y == 0), and all possible combinations with these variations.What is going on:
As you already know, myRB.velocity.y is positive when jumping, and negative when falling. In theory, with gravity as acceleration, the velocity should gradually reduce from the initial positive value (when the jump starts), until the character reaches the peak of its jump, when, in that exact moment, the velocity equals 0, and then the player starts descending with increasing (in the negative direction) velocity.After some practical tests, the function only logs “apex” when the character hits its head on a platform above him or when he falls off a platform (only sometimes)…
Tl;dr:
myRB.velocity.y __ does not __ equals 0 when the character reaches its jump peak. How can I check if he reached its jump apex via C# script?Thanks!