Hi!
I have a game I am working on and the player is a sphere. I already have the roll-a-ball camera setup but I want the camera to rotate to face the way the ball is moving. The game uses the new Unity input system.
any ideas?
Hi!
I have a game I am working on and the player is a sphere. I already have the roll-a-ball camera setup but I want the camera to rotate to face the way the ball is moving. The game uses the new Unity input system.
any ideas?
Use Mathf.Atan2() to determine the heading (in radians) of the ball motion.
Use the Mathf.Rad2Deg to get it in degrees so you can reason about it.
If the ball’s speed is above an amount you consider worth turning the camera, use Mathf.MoveTowardsAngle() to slew the camera heading to the velocity heading you calculated above.
Slew it by an amount that a) suits your tastes, and b) is scaled according to Time.deltaTime.
This script inside my proximity buttons package (fully available on github) does basically exactly this based on your character’s motion:
See lines 138 or thereabouts in the above snippet.
Thanks very much! I’ll try that!