hello, i’ve made an isometric camera, and when my player moves, the camera follows him. how can i change the distance between the player and the camera, and keep the player at the center of the camera as usual?
cam code:
public var player:GameObject;
//The offset of the camera to centrate the player in the X axis
public var offsetX = -2;
//The offset of the camera to centrate the player in the Z axis
public var offsetZ = -20;
//The maximum distance permited to the camera to be far from the player, its used to make a smooth movement
public var maximumDistance = 1;
//The velocity of your player, used to determine que speed of the camera
public var playerVelocity = 20;
private var movementX;
private var movementZ;
// Update is called once per frame
function Update ()
{
movementX = (player.transform.position.x + offsetX - this.transform.position.x)/maximumDistance;
movementZ = (player.transform.position.z + offsetZ - this.transform.position.z)/maximumDistance;
if (maximumDistance >=1)
{
this.transform.position += new Vector3((movementX * playerVelocity * Time.deltaTime), 0, (movementZ * playerVelocity * Time.deltaTime));
}
else
{
maximumDistance = 1;
this.transform.position += new Vector3((movementX * playerVelocity * Time.deltaTime), 0, (movementZ * playerVelocity * Time.deltaTime));
}
}
thank you