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

644
Vistas
Unity 3d my character does not rotate to the raycasthit point I drew

I draw a rail on my central character with the direction of the front of my camera. I use Rigidbody.LookRotation to make the character return to that point, but it doesn't.

private void Update()
{
    Physics.Raycast(transform.position + new Vector3(0, 3, 0), mainCam.transform.forward, out hit);
    Quaternion lookrotation = Quaternion.LookRotation(new Vector3(hit.point.x,0,hit.point.z));
    transform.rotation = Quaternion.Slerp(transform.rotation, lookrotation, Time.deltaTime * 2);
    Debug.DrawLine(transform.position + new Vector3(0, 3, 0),hit.point);
    Debug.Log(hit.collider.gameObject.name);
}

My Scene

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

At first glance there are two points:

  1. LookRotation expects a forward direction .. currently you only give it a position.

    you would rather want to use e.g.

    if(Physics.Raycast(transform.position + new Vector3(0, 3, 0), mainCam.transform.forward, out var hit))
    {
        var direction = hit.point - transform.position;
        direction.y = 0;
        var lookrotation = Quaternion.LookRotation(direction);
        ...
    }
    
  2. currently you also rotate just real slow. Assuming 60 Fps Each frame you interpolate with a factor of about 1/60 * 2 so about 0.033.. from the current towards the target rotation. So this gets even slower the closer you get to the target rotation.

    You would rather either not multiply by Time.deltaTime but use a constant factor e.g. 0.5f

    or use RotateTowards and provide a continous anglePerSecond * Time.deltaTime.

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