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

61
Visualizações
Unity FPS Movement

I created a rigidbody fps controller by youtube tutorial and everything works fine except diagonal movement as it x1,4 speed bugged. So i tried vector3.normalized and vector3.ClampMagnitude but seems this is not an option for my fps controller solution as speed becomes constant and unchangable. Original code:

    x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
    z = Input.GetAxis("Vertical") * speed * Time.deltaTime;

    Vector3 moveVec = orientation.right * x + orientation.forward * z + Vector3.up * rb.velocity.y;      
    rb.velocity = moveVec;

So i tried this

    x = Input.GetAxis("Horizontal") ;
    z = Input.GetAxis("Vertical");

    Vector3 moveVec = Vector3.ClampMagnitude(orientation.right * x + orientation.forward * z + 
    Vector3.up * rb.velocity.y, 1.0f) * speed * Time.deltaTime;      
    rb.velocity = moveVec;   

And it worked but when i hit an object and some random Y transform accures i fly in the air as rb.velocity is also multiplyed on speed and deltaTime. Any tips?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Separate your Input from the current velocity and apply the speed multiplier only to the input.

Note that you are dealing with a velocity which is in Unity Unit per second. => You do not want to multiply by Time.deltaTime here!

x = Input.GetAxis("Horizontal");
z = Input.GetAxis("Vertical");

Vector3 moveVec = Vector3.ClampMagnitude(orientation.right * x + orientation.forward * z, 1.0f) * speed;
moveVec += Vector3.up * rb.velocity.y;    
rb.velocity = moveVec;
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