Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!