Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class CameraFollow : MonoBehaviour
- {
- public Transform target;
- public float smoothSpeed = 0.125f;
- public Vector3 locationOffset;
- public Vector3 rotationOffset;
- void FixedUpdate()
- {
- Vector3 desiredPosition = target.position + target.rotation * locationOffset;
- Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
- transform.position = smoothedPosition;
- Quaternion desiredrotation = target.rotation * Quaternion.Euler(rotationOffset);
- Quaternion smoothedrotation = Quaternion.Lerp(transform.rotation, desiredrotation, smoothSpeed);
- transform.rotation = smoothedrotation;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement