Advertisement
LittleAngel

SmoothF

Jan 4th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SmoothFollow : MonoBehaviour {
  5.  
  6. public Transform target;
  7. public float distance;
  8. public float height;
  9. public float damping;
  10. public bool smoothRotation;
  11. public float rotationDamping;
  12. public Vector3 cameraOffset;
  13.  
  14. void LateUpdate (){
  15. Vector3 wantedPosition = target.TransformPoint (0, height, -distance);
  16. transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
  17.  
  18. if (smoothRotation) {
  19. Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
  20. transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
  21. }
  22.  
  23. else transform.LookAt (target, target.up);
  24. }
  25.  
  26. void Reset () {
  27. distance = 3.0f;
  28. height = 3.0f;
  29. damping = 5.0f;
  30. smoothRotation = true;
  31. rotationDamping = 10.0f;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement