So I have this project where i’m using a ball as a player controlled character, but when I give the scene a camera it spins with the ball’s movement. Does anyone know a way to have the camera follow behind the ball but not rotate or spin?
First set the position of camera and ball as your desiring distance between them. The offset value of the script below is be calculated on Start method and protect distance between ball and camera as at first.
Camera and ball must be separate objects. There musn’t be parent and child relationships.
Add the script below to Camera object.
public class CameraFollow : MonoBehaviour {
public Transform targetBall;
private Vector3 offset;
private void Start()
{
offset = transform.position - targetBall.position;
}
private void Update()
{
transform.position = targetBall.position + offset;
}
}