duck

Unity 3d Mouselook Pivot

Feb 27th, 2013
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MouseLookPivot : MonoBehaviour {
  5.    
  6.     public float turnSpeed = 1;
  7.     public float tiltRange = 45;
  8.    
  9.     float lookAngle = 0;
  10.     float tiltAngle = 0;
  11.    
  12.  
  13.     // Update is called once per frame
  14.     void Update () {
  15.    
  16.         float x = Input.GetAxis("Mouse X");
  17.         float y = Input.GetAxis("Mouse Y");
  18.        
  19.         lookAngle += x*turnSpeed;
  20.         tiltAngle += y*turnSpeed;
  21.        
  22.         tiltAngle = Mathf.Clamp (tiltAngle, -tiltRange, tiltRange);
  23.        
  24.         transform.rotation = Quaternion.Euler( tiltAngle, lookAngle, 0);
  25.        
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment