- Home /
Question by
Frendyy · Mar 24, 2019 at 10:52 AM ·
controllerjump
I also used to check is grounded raycast and OnCollisionEnter2D but still there was such a problem.
I call the Jump () function using Input.GetAxisRaw ("Vertical"). But this function is called several times and the character jumps 3 times higher. I also used to check is grounded raycast and OnCollisionEnter2D but still there was such a problem.
void Update()
{
int yMovement = (int)Input.GetAxisRaw("Vertical");
if (yMovement == 1)
{
Jump();
}
isGrounded = Physics2D.OverlapArea(new Vector2(transform.position.x - 0.5f, transform.position.y - 0.5f), new Vector2(transform.position.x + 0.5f, transform.position.y - 0.51f), groundLayer);
}
void Jump()
{
if (!isGrounded)
{
return;
}
else
{
print("jump");
transform.localScale = new Vector2(1, 1);
r.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
isGrounded = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Custom Character Script Allowing Movement in the Air? 0 Answers
How do I make this jump function work? 1 Answer
Jumping and maintaining current velocity 1 Answer
C# Jumping Issue 1 Answer
script for Jump help 3 Answers