Hi, this is my code for jump and double jump, it works perfectly but cannot control the height of the jump. What I’m looking for is a maximum height the character reaches if I press the jump button long enough and variable height if I let go the jump button before the max height.
if (Input.GetKeyDown ("space"))
{
if (is_Grounded)
{
is_Grounded = false;
cir_Grounded = false;
cir_GroundedS = false;
m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, 0); //need to kill velocity on y axis so I can apply a full force on the doube jump
m_Rigidbody2D.AddForce (new Vector2(0f, m_JumpForce));
doubleJump = true;
}
else if (doubleJump)
{
m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, 0);
m_Rigidbody2D.AddForce (new Vector2(0f, m_JumpForce));
doubleJump = false;
}
}
this is my actual code, the character has a rigidbody which is affected by gravity. Does anyone have any idea how to control the height?