So I wrote this custom 2D smooth camera follow script, but as soon as the camera is supposed to follow the player object the player object its self seems to jerk around. This is a visual effect and not a product of the script i’m using to actually move the character, I am sure of that.
My best guess is that something is causing the camera to interpolate between positions between frames, (I.E. the transform.position is being changed from zero to the position of the player), I cannot seem to locate the issue. So I turn to you! The script is below feel free to test it/keep it, but please help me find what is wrong.
using UnityEngine;
using System.Collections;
public class cameraMechanics : MonoBehaviour {
public float camDist, slugRate, slugFollowRate;
public Transform mainObject;
Vector3 camPos;
Transform follow;
void Start(){
camPos = transform.position;
follow = mainObject;
}
void Update(){
float dist = Vector2.Distance((Vector2)camPos, (Vector2)follow.position);
if(dist > slugRate){
Vector2 cPS = (Vector2)camPos;
cPS += ((Vector2)camPos - (Vector2)follow.position) * (slugFollowRate * dist);
camPos = (Vector3)cPS;
}
camPos.z = camDist;
transform.position = camPos;
}
}
Thank you in advance for any advice or help!