Hi !
I have a rigidbody2D to which I apply this jump routine :
IEnumerator JumpRoutine()
{
Vector2 jumpVector = new Vector2 (0f, jumpForce);
// === Velocity Cut ===
// source : http://gamasutra.com/blogs/DanielFineberg/20150825/244650/Designing_a_Jump_in_Unity.php
// Add force on the first frame of the jump
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce(jumpVector, ForceMode2D.Impulse);
// Wait while the character's y-velocity is positive (the character is going up)
while(isPressingJump && rigidbody2D.velocity.y > 0)
{
yield return null;
}
// [not important] If the jumpButton is released but the character's y-velocity is still positive...
if (rigidbody2D.velocity.y > 0)
{
//...set the character's y-velocity to 0;
rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0);
}
}
Basically, it applies a force impulse of `jumpForce` when the user presses Jump. As long as the user keeps the Jump key down, the rigidbody2D acts like normal (going as high as the initial force impulse allows him to). But when he releases the key, the rigidbody2D brutally stops going up (y-velocity to 0).
I tried to calculate the maximum height the rigidbody2D can reach if the user keeps the Jump key down long enough.
Is there a way to simulate/predict the jump and place a mark at the rigidbody's future position ? Or can it be calculated with some physics ?
(My goal is to draw a debug line showing the max height the player can reach with a jump).
Thanks!
Seeven.
↧