- Home /
Player jump not working correctly
I'm making a game in Unity 3D and I have this script attached to my player to make him jump when the Up arrow is pressed:
private Rigidbody rb;
public float jumpForce;
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
PlayerMovement();
Jump();
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("This if works");
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
My player has a rigidbody attached to it and I know the if statement works because of that debug.log, however, nothing happens when I press the up arrow. Anyone know why? Let me know if you need any more info about the script or the player object. Thanks for your help!
usual checks: is jumpForce > 0, is Rigidbody isKinematic = False, is Rigidbody position constraint (Y) unchecked, is useGravity enabled and if it is then check that the jumpForce is big enough in relation to the mass. Are you using also navmesh + agent? if so then this can also mess with physics.
Also what are you doing in the Player$$anonymous$$ovement()? This can also "negate" the physics effect depending what your are doing there...
Thanks I had isKinematic = true. Didn't know that would do that.
Answer by mbro514 · Jul 03, 2020 at 11:39 PM
I think that your problem is that you didn't assign the variable "rb" to the rigidbody attached to the player.
Oh sorry forgot to mention in there that I do have that. I'll edit my post.
Your answer
Follow this Question
Related Questions
I need help with a movement script 1 Answer
Another Slow Fall Problem... 2 Answers
Player wont jump (visual script),2d player does not jump (visual script) 1 Answer
Jumping only once (2D) 2 Answers
change multiple jump to single jump 1 Answer