My camera is in top-down view with 50X rotation degrees. I have 2 problems.
My camera follow the player and I have defined the limits of the camera so that it does not go beyond certain values. Currently the X limit working well and my camera X axis is center on the player. BUT for the Z axis does not work.
My start camera value is: -29, 20 (height, never changes), -23.
When I press play button, my camera value is: -29, 20, -11. Why -11?
-11 is my bottom limit and -43 my top limit.
How to use a smoothing camera code like “lerp” with “clamp”? I want to have a smooth camera move, who not move instantly when the player move.
The code:
using UnityEngine;
/*---------------*/
public class CameraFollow : MonoBehaviour {
/*---------------*/
public Transform Target;
/*-----------------------------------------------------*/
void FixedUpdate () {
transform.position = new Vector3(Mathf.Clamp(Target.position.x, -70, -17), 20, Mathf.Clamp(Target.position.z, -11, -43));
}
/*-----------------------------------------------------*/
}
That’s because you’ve got bad settings on your character. Set it’s rigidbody to interpolate or extrapolate, as otherwise it only moves the player object in FixedUpdate - which will cause it to visibly jump around.