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

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

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 Relatório

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 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