How to rotate a sphere while moving?

I have sphere and I want it to rotate in the direction it is moving. How do I do it. I want it when I press the up key it moves forward and rotate forward and when I press the down key it moves backward and rotate backward.

If the ball is controlled by a rigidbody, you can just apply force and it will rotate naturally as it collides with other objects in the scene.

If you are moving the ball by adjusting its transform position, you can rotate the transform according to that movement:

float radius = ...radius of the sphere
float moved = ...some number representing how far we've moved

//ball should rotate this many times
float rotations = moved / (Mathf.PI * radius);

For example, a ball with radius 1 which moves 3.14 units will do approximately one full spin. Another ball with double the radius would spin about half as far.

If you know your trig, you’ll remember that pi relates a circle’s radius to its circumference. This is handy for converting between angular and linear velocity.

If the ball is moving on multiple axes, it will need to spin on multiple axes.

If all of this is overwhelming, just attach the rigidbody and be done with it. :wink:

CLICK ME for a great tutorial that shows just what you are asking for.