Advertisement
JuiceBoxx

Other Camera Script

Mar 17th, 2015
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1.  using UnityEngine;
  2. using System.Collections;
  3. public class FollowCamera : MonoBehaviour {
  4. public float interpVelocity;
  5. public float minDistance;
  6. public float followDistance;
  7. public GameObject target;
  8. public Vector3 offset;
  9. Vector3 targetPos;
  10. // Use this for initialization
  11. void Start () {
  12. targetPos = transform.position;
  13. }
  14. // Update is called once per frame
  15. void FixedUpdate () {
  16. if (target)
  17. {
  18. Vector3 posNoZ = transform.position;
  19. posNoZ.z = target.transform.position.z;
  20. Vector3 targetDirection = (target.transform.position - posNoZ);
  21. interpVelocity = targetDirection.magnitude * 5f;
  22. targetPos = transform.position + (targetDirection.normalized * interpVelocity * Time.deltaTime);
  23. transform.position = Vector3.Lerp( transform.position, targetPos + offset, 0.25f);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement