Guest User

Untitled

a guest
May 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @script RequireComponent(CharacterController)
  2. @script AddComponentMenu ("Camera-Control/Mouse Look")
  3. enum RotationAxe { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
  4. var axes = RotationAxe.MouseXAndY;
  5. var sensitivityX : float = 2;
  6. var sensitivityY : float = 2;
  7.  
  8. var minimumX : float = -360;
  9. var maximumX : float = 360;
  10.  
  11. var minimumY : float = -60;
  12. var maximumY : float = 60;
  13.  
  14. var rotationX : float = 0;
  15. var rotationY : float = 0;
  16.  
  17. private var originalRotation : Quaternion;
  18.  
  19. //Tastaturbewegung
  20. private var controller : CharacterController;
  21. private var dir : Vector3 = Vector3.zero;
  22. var speed : float = 6;
  23. var gravity : float = 9.81;
  24. var rennen :float = 2;
  25. var rotatation : Transform;
  26.  
  27.  
  28. function Awake()
  29. {
  30.     controller = GetComponent(CharacterController);
  31. }
  32.  
  33.  
  34.  
  35. function Update () {
  36.     if (axes == RotationAxe.MouseXAndY && Input.GetKey(KeyCode.Mouse1)) {
  37.         rotationX += Input.GetAxis("Mouse X") * sensitivityX;
  38.         rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
  39.        
  40.         rotationX = ClampAngle (rotationX, minimumX, maximumX);
  41.         rotationY = ClampAngle (rotationY, minimumY, maximumY);
  42.        
  43.         var xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
  44.         var yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
  45.        
  46.         transform.localRotation = originalRotation * xQuaternion * yQuaternion;
  47.     }
  48.     else if (axes == RotationAxe.MouseX && Input.GetKey(KeyCode.Mouse1)) {
  49.         rotationX += Input.GetAxis("Mouse X") * sensitivityX;
  50.         rotationX = ClampAngle (rotationX, minimumX, maximumX);
  51.        
  52.         xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
  53.         transform.localRotation = originalRotation * xQuaternion;
  54.     }
  55.  
  56.    
  57.    
  58.    
  59.    
  60.    
  61.     // Tastaturbewegung
  62.     dir.x = 0;
  63.     dir.z = 0;
  64.  
  65.     if(controller.isGrounded) //auf dem Boden
  66.     {
  67.         dir.y = -1;
  68.         if(Input.GetKey("e"))
  69.         {
  70.             dir.x = 1 * speed;
  71.            
  72.         }
  73.        
  74.         if(Input.GetKey("q"))
  75.         {
  76.             dir.x = -1 * speed;
  77.         }
  78.         if(Input.GetKey("w"))
  79.         {
  80.             dir.z = 1 * speed;
  81.         }
  82.         if(Input.GetKey("s"))
  83.         {
  84.             dir.z = -1 * speed;
  85.         }
  86.         if(Input.GetKey("a"))
  87.         {
  88.             transform.Rotate(0, -100 * Time.deltaTime, 0);
  89.             controller.SimpleMove(transform.TransformDirection(dir));
  90.            
  91.         }
  92.         if(Input.GetKey("d"))
  93.         {
  94.             transform.Rotate(0, 100 * Time.deltaTime, 0);
  95.             controller.SimpleMove(transform.TransformDirection(dir));
  96.         }
  97.     }
  98.    
  99.     else //in der Luft
  100.     {
  101.         dir.y -= gravity * Time.deltaTime;
  102.     }
  103.     controller.Move(dir * Time.deltaTime);
  104. }
  105.  
  106. function Start () {
  107.     if (rigidbody)
  108.     rigidbody.freezeRotation = true;
  109.     originalRotation = transform.localRotation;
  110. }
  111.  
  112. static function ClampAngle (angle : float, min : float, max : float) : float {
  113.     if (angle < -360.0)
  114.     angle += 360.0;
  115.     if (angle > 360.0)
  116.     angle -= 360.0;
  117.     return Mathf.Clamp (angle, min, max);
  118. }
Add Comment
Please, Sign In to add comment