Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

62
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda