Advertisement
Guest User

Camera script

a guest
Oct 28th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1.     float height = 3f;
  2.     float distance = 5f;    
  3.  
  4.     private void Start()
  5.     {
  6.         myCollider = GetComponent<BoxCollider>();
  7.         myRigidboy = GetComponent<Rigidbody>();
  8.  
  9.         myCollider.enabled = false;
  10.         myRigidboy.isKinematic = true;
  11.  
  12.         positionDamping = 10f;
  13.         rotationDamping = 10f;
  14.  
  15.         StartCoroutine(LateFixedUpdate());
  16.     }
  17.  
  18.     IEnumerator LateFixedUpdate()
  19.     {
  20.         while(true)
  21.         {
  22.             yield return new WaitForFixedUpdate();
  23.             Follow();
  24.         }
  25.     }
  26.  
  27.     void Follow()
  28.     {      
  29.         //wantedRotation = Quaternion.LookRotation(3Dobject.position -transform.position, 3Dobject.up);     //  Cam turns with ship
  30.         wantedRotation = Quaternion.LookRotation(3Dobject.position - transform.position);        //  Cam stays on global up
  31.         wantedPosition = 3Dobject.TransformPoint(0, height, -distance);
  32.  
  33.         transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
  34.         transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * positionDamping);
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement