Camera Follow Object While Looking At Other Target

I have a sphere object that can freely move around which I can easily follow with the camera. (This is easy)
The sphere object needs to be moved to a certain position for the player to earn score. (This is easy)
I can follow the sphere with the camera while looking at the target position. (This is easy too.)

Basically I just added a follow script to the camera and targeted the sphere then added LookAt code to the script that makes the camera look at the target position.

The part that I haven’t been able to figure out is:

Always have the freely rolling around sphere between the camera and the target position. So the player is able to see the sphere and target at all times. While the sphere is rolling around freely the player has no control over the sphere’s movement. (A bit like billiards)

I have added a dummy object inside the sphere to get the rotation of the lookat value of the Y axis and copied that to the camera’s Y axis. This helps but the sphere is cant be seen after the ball passes by the target and the angle is too much as there is a set distance between the camera and the sphere.


Any ideas? I am lost to how to calculate the relative position of the camera to the sphere while looking at target.

Say you have the game objects of the target, the sphere and the camera. You can calculate a position that will keep them in a row as follows:

var v3T = sphere.transform.position - target.transform.position;
camera.transform.position = sphere.transform.position + v3T.normalized * camera_distance;

where camera_distance is the distance you want between the camera and the sphere.

robertbu your solution works like a charm. Much faster than SmoothFollow for sure and easy to customize! Thanks…