how to make camera follow player unity 3d code example
Example 1: how to make camera follow player unity 2d
public class CameraFollow : MonoBehaviour {
public GameObject Target;
private Vector3 Offset;
void Start() {
Offset = transform.position - Target.transform.position;
}
void Update() {
transform.position = Target.transform.position+Offset;
}
}
Example 2: camera follow player unity smooth
Vector3.SmoothDamp(cam.position, transform.position + cameraOffset, ref cameraVelocity, CameraFollowSmoothTime);
cam.position = cam.position + cameraVelocity * Time.deltaTime;