duck

Unity 3D javascript very simple mouse look script

Jul 28th, 2011
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Performs a mouse look.
  2.  
  3. var horizontalSpeed : float = 2.0;
  4. var verticalSpeed : float = 2.0;
  5.  
  6. var x : float = 0;
  7. var y : float = 0;
  8.  
  9. function Update () {
  10.  
  11.     // Get the mouse delta. This is not in the range -1...1
  12.     var h : float = horizontalSpeed * Input.GetAxis ("Mouse X");
  13.     var v : float = verticalSpeed * Input.GetAxis ("Mouse Y");
  14.    
  15.     x = Mathf.Clamp(-30, 30, x+v );
  16.     y = Mathf.Clamp(-90, 90, y+h );
  17.    
  18.     transform.rotation = Quaternion.Euler(x,y,0);
  19.    
  20. }
Advertisement
Add Comment
Please, Sign In to add comment