Hi,
I am currently using a camera to track a golf ball in the air. The camera tracks the ball from above and then when gravity gets the better of the ball, it drops away from the camera leaving a view in the sky of the ball on the fairway below. My camera then begins to zoom back to the (close-up) distance to the ball as specified in the script, zooming quickly (as i have specified).
How can I tween the camera to a stop when it reaches the ball again? Looks pretty crude at the minute.
Here is the script I am using:
var myCamera : Transform;
var target : Transform;
var desiredDist = 7;
var minDist = 7;
var maxDist = 1000;
var speed = 40;
function Update ()
{
var f = Mathf.MoveTowards(myCamera.position.y - target.position.y, desiredDist, speed * Time.deltaTime);
f = Mathf.Clamp(f, minDist, maxDist);
myCamera.position = target.position + Vector3(0, f, 0);
}
At the minute the camera just crashes to a stop with this method. There is also a little ‘judder’ when the ball falls past the desired distance too, that I’m trying to smooth out, but as I’m quite new to JS I just can’t figure it out. Thanks for any help.