- Home /
Zoom camera out as player approaches large objects
Hi all,
The camera in my game is an isometric viewpoint and due to it's nature it makes it difficult to see large buildings when the character is close to them.
What would be the best way to have the camera zoom out as the player approaches the building object?
Any help is much appreciated.
Thanks
Answer by GameVortex · Nov 14, 2013 at 07:24 PM
The first way i thought of would be to translate the distance the player is from big objects to the distance the camera should be at:
public Transform bigObject;
public Transform player;
public float minCamDistance;
public float maxCamDistance;
public float bigObjectMinimumDistance;
public float GetCameraDistance()
{
float distancetoObject = Vector3.Distance(bigObject.position, player.position);
float cameraDistance = Mathf.Lerp(maxCamDistance, minCamDistance, distanceToObject / bigObjectMinimumDistance);
return cameraDistance;
}
Now all you have to do is position your camera using the distance you get in GetCameradistance(); The camera should move at the same rate as the player moves closer to the big object. To have it work for multiple big objects, you would have to check the distance to all of them and then use the one the player is closest to in the Mathf.Lerp function.
Your answer
![](https://koobas.hobune.stream/wayback/20220613121910im_/https://answers.unity.com/themes/thub/images/avi.jpg)