Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda