Unity camera follow on cylinder

Viewed 168

I have a mini project where a ball goes around a cylinder while moving forward on the cylinder. I want my camera to follow the ball and rotate towards the ball while in cameras point of view cylinder is always forward. So for example if the ball goes to the right i want the camera to follow the ball to the right but point at the cylinder all the time and not rotate with ball to the right same problem like here: https://answers.unity.com/questions/1680243/camera-follow-ball-along-cylinder.html

I have a code but doesn't work the way I want.

Transform target;
public Transform pos;
public float speed = 10f;
void Start(){
    //ball's transform
    target = GameObject.FindGameObjectWithTag ("Player").transform;
}
void LateUpdate(){

    Vector3 rot = Quaternion.LookRotation (target.position - transform.position).eulerAngles;
    rot.z = 0;
    transform.rotation = Quaternion.Euler (rot);


}
void FixedUpdate(){
    //sets the camera position to the position of the child object of the 
    //ball
    transform.position = pos.position;
}
0 Answers
Related