Hi,
I am trying to track a ball from above (golf game) with my camera. I have easily done this with parenting the ball to the camera so the camera is a child - but I’d like the camera to have a little flexibility on the Y axis, so I can see the ball grow and shrink as it goes higher and lower.
My other idea is to change the size of the ball object whilst at various heights, but again - im not sure how to do this smoothly.
Has anybody had experience with this at all?
Thanks for reading.
Korpers
1 Answer
1
Here is a bit of untested code to show you what I was talking about. You’ll have to play with the parameters in the Inspector to get something that feels right or your situation.
var myCamera : Transform;
var target : Transform;
var desiredDist = 20.0;
var minDist = 5.0;
var maxDist = 25.0;
var speed = 30.0;
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);
}
It is difficult to offer specifics without your code. I'd do a combination of Vector3.Lerp to create a bit of lag in the y movement along with creating a minimum distance to the ball.
– robertbuOoops, yes that would of been a good idea wouldn't it. Here is the super basic code: #pragma strict var myCamera : Transform; var target : Transform; function Update () { myCamera.position = target.position + Vector3(0, 20, 0); } I'll try putting Lerp into the Vector3 class (is it a class?) now. Thanks for answering.
– Korpers