I have a ball moving on a flat plane. I cannot use RigidBody physics, so my object in Kinematic and I am manually handling speed/acceleration. The linear movement of the ball is fine, however as the ball does not rotate, it looks odd.

Given a speed Vector3, where I am moving on the X & Z, I need to figure out how to make the ball "roll".

I think I a running into Euler / Gimbal lock issues by trying this:

  180.0f *  speed.z / (Mathf.PI * radius) * dt,
  -180.0f * speed.x / (Mathf.PI * radius) * dt

This formula is loosely based on the angular velocity formula and converting to degree's per second, with dt (deltaTime).

My gut instinct says that the solution may lie in Quaternions somewehere...?!


From http://answers.unity3d.com/answers/880349/view.html

  Vector3 axis = Vector3.Cross(speed, Vector3.down);
  float angle = (speed.magnitude * 360 / circumference);
  transform.Rotate(axis, angle * dt, Space.World);

(where speed is a Vector3 and circumference is... well.. the circumference of your ball).

The Cross part gives you the axis on which you need to rotate around. The Space.World part is important too.


Feels like there should be a better way than this?

transform.LookAt(transform.position + speed);
r += 180.0f * speed.magnitude / (Mathf.PI * radius) * dt;
transform.Rotate(Vector3.right, r);

(r is a protected float on the GameObject which I can simply increment to rotate "to" the right angle)

  • \$\begingroup\$ Note: Turns out this looks rubbish at low speeds. The ball "turns" to face the way it's rolling. That's now how balls work ;) \$\endgroup\$
    – Nick
    Nov 28 '16 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.