daily pastebin goal
33%
SHARE
TWEET

Camera Bug

a guest Mar 20th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class CameraController : MonoBehaviour {
  2.  
  3.     public GameObject target;
  4.     public float rotateSpeed;
  5.     Vector3 offset;
  6.  
  7.     void Start() {
  8.         offset = target.transform.position - transform.position;
  9.     }
  10.  
  11.     void LateUpdate() {
  12.         float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
  13.  
  14.         target.transform.Rotate(0, horizontal, 0);
  15.  
  16.         float desiredAngle = target.transform.eulerAngles.y;
  17.         Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
  18.         transform.position = target.transform.position - (rotation * offset);
  19.  
  20.         transform.LookAt(target.transform);
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top