So I am trying to make a smooth follow camera
public class CameraFollow : MonoBehaviour { Transform player; Transform cam; float x = 4f; float y = 5f; float smoothX; float smoothY; float velocity = 0; public float smoothTime = 0.05f; void Awake() { cam = GetComponent<Transform>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>(); } void FixedUpdate() { smoothX = Mathf.SmoothDamp(cam.position.x, player.position.x, ref velocity, smoothTime, 15f); smoothY = Mathf.SmoothDamp(cam.position.y, player.position.y, ref velocity, smoothTime, 15f); } void LateUpdate() { cam.position = new Vector3(Mathf.Clamp(smoothX, -x, x), Mathf.Clamp(smoothY, -y, y), -10f); } }
But its behaving weird when I move right or up. For example if I move to the right it seems to follow with some weird offset on the y (if that makes sense :P)
However it works perfect when moving left or down.
Here’s a little demo of it:
https://googledrive.com/host/0Bzct6cQnrUORbmNwTWFSU
Been trying to figure this out for a couple of hours now and getting nowhere 🙁