- Home /
Question by
RealEfrain12 · Nov 25, 2020 at 07:55 PM ·
c#playerjump
Jump Issue
I need my player to jump, but everytime I hit space to jump, my player just doesnt jump, I can walk just fine but I can't Jump. Here is my code (C#)
private void Jump()
{
if (grounded && readyToJump)
{
readyToJump = false;
//Add jump forces
rb.AddForce(Vector2.up * jumpForce * 1.5f);
rb.AddForce(normalVector * jumpForce * 0.5f);
//If jumping while falling, reset y velocity.
Vector3 vel = rb.velocity;
if (rb.velocity.y < 0.5f)
rb.velocity = new Vector3(vel.x, 0, vel.z);
else if (rb.velocity.y > 0)
rb.velocity = new Vector3(vel.x, vel.y / 2, vel.z);
Invoke(nameof(ResetJump), jumpCooldown);
}
}
private void ResetJump()
{
readyToJump = true;
}
Comment
Are you sure readyToJump
is set to true when your script gets initialised (when declaring the bool / Awake / OnEnable / Start / ...). Same for grounded
.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How do I cap jumping? 1 Answer
[C#] JUMP - What i must add to this code to jump? :> 1 Answer
Distribute terrain in zones 3 Answers
I Want My Player To Be Sent Flying In The Air When He Get's Hit By An Enemy 1 Answer