Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
unity - jump with rigidbody bug

I am trying to jump with rigidbody, and sometimes my jump is low like it stacks in something and sometimes is high. Why does it change?

thank's for the answers

My code:

private void Update() {

    if (Input.GetKeyDown(KeyCode.Space) && isGrounded) Jump();
}

private void FixedUpdate()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, groundMask);
}

private void Jump()
    {
        rigidbody.AddForce(Vector3.up * 20, ForceMode.VelocityChange);
        isGrounded = false;
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First of all, any Physics calculations regarding Rigidbody (such as the one in your Jump()) should always be done inside the FixedUpdate() function according to the Unity documentation here. FixedUpdate() runs at a default fixed rate every 0.02 seconds, whereas Update() runs once per frame, which would be different for every machine it runs on.

Instead of me reinventing the wheel for you, I done a search and found the following code on the Unity forums, here, which should help you understand your problem further. I used the code there and edited it for your scenario.

private bool shouldJump = false;

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
    {
       shouldJump = true;
    }
}

void FixedUpdate()
{
    // Check for jump
    if (isGrounded && shouldJump)
    {
        shouldJump = false;

        rigidbody.AddForce(Vector3.up * 20.0f, ForceMode.VelocityChange);
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!