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

358
Vistas
How to use transform.forward that only acknowledges one axis of rotation?

I am making a rolling ball game, and the way I want it to work is based on constant forward movement and rotation based turning. I'm using force, which then has the ball roll forward. My Issue here is that I would like the ball to move forward based on where it's "facing". Using Vector3.forward only moves it according to world space and transform.forward will start going backwards because the ball rolls over, upside down. How can I make it so transform.forward ignores my forward turning, only being effected by the sideways turning?

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

0

"forward" is hard to imagine on a sphere.

You add speed when rotating around the X-axis (ball moves "forward") For direction control, you rotate around global Y-axis. The transform.forward will spin around the object. But the transform.right (local x-axis so to say) stays stable. So we only need the Vector3.Cross Product of the transform.right and the global Vector3.Up.

Vector3 forward = Vector3.Cross(transform.right, Vector3.up);
over 4 years ago · Santiago Trujillo Denunciar

0

You can use vector math for this. Take the cross product between the local right and the world up:

private static Vector3 GetRollingForward(Vector3 localRight)
{
    return Vector3.Cross(localRight, Vector3.up);
}

// ...

void Update()
{
    Debug.DrawLine(transform.position, transform.position 
            + GetRollingForward(transform.right));
}
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