- Home /
Camera Rotate behind rotating ball
Okey so let me to the math. I just need solution to specific problem. I have rotating ball (bouncing around and do much funny stuff) and I need to be camera behind her movment. So if Ball is going forward, camera must be backward and facing it. I am not sure how to do taht with Rigidbody.velocity so camera will keep specific distance from ball but still focus her from back side of her movment.
why not add a camera on your ball object and just position it behind?
Answer by OrbitGames · Jul 31, 2015 at 01:23 PM
First get the rigidbody.velocity, and normalize it, so the magnitude is 1. Then multiply the distance on it.
Next you might want to do some fancy lerping camera movement.
Last to let the camera face your ball use transform.LookAt().
Leaving out step two, it would look something like this (untested):
float distance = 5;
Transform Target = ballGameObject;//obviously set this somehow else
transform.position = Target.position - Target.getComponent<Rigidbody>().velocity.normalized * distance;
transform.LookAt(Target.position);