I have written a custom camera follow script which deals with specific requirements within my game. The camera smoothly tracks the player position, however surrounding geometry appears to “jitter” and the further away geometry is, the worse the problem appears.
I understand why this happens, moving the camera a little close up makes a larger jump further away.
What can I do to minimize this undesired effect?
In my experience with this the main problems come from either Lerping or the Function the lines are contained in:
Steps to Make Movement smooth:
- Lerp positions:
var nextPosition: Vector3; //or public Vector3 nextPosition; if in C#
var moveSpeed: float; //or public float moveSpeed; if in C#
transform.position = Vector3.Lerp(transform.position, nextPosition, Time.deltaTime * moveSpeed);
- Use an Update function instead of LateUpdate or FixedUpdate:
function Update() //Or void Update() if in C#
- Use Time.deltaTime as its smoother than Time.time:
Time.deltaTime;
I really hope I could help be sure to ask if any further Questions.
Best way to smooth camera movement in untiy2D…
transform.position=Vector3.SmoothDamp(new Vector3(transform.position.x,transform.position.y,-10f),
new Vector3(player.transform.position.x,player.transform.position.y,-10f),
ref velocity, smoothTime);