Advertisement
kasru

Flycam

Jan 11th, 2013
3,975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //****** Donations are greatly appreciated.  ******
  2. //****** You can donate directly to Jesse through paypal at  https://www.paypal.me/JEtzler   ******
  3.  
  4. var mainSpeed : float = 100.0; //regular speed
  5. var shiftAdd : float = 250.0; //multiplied by how long shift is held.  Basically running
  6. var maxShift : float = 1000.0; //Maximum speed when holdin gshift
  7. var camSens : float = 0.25; //How sensitive it with mouse
  8. private var lastMouse = Vector3(255, 255, 255); //kind of in the middle of the screen, rather than at the top (play)
  9. private var totalRun : float  = 1.0;
  10.  
  11. function Start (){
  12.     Screen.showCursor = false;
  13. }
  14.  
  15. function Update () {
  16.  
  17.     lastMouse = Input.mousePosition - lastMouse ;
  18.     lastMouse = Vector3(-lastMouse.y * camSens, lastMouse.x * camSens, 0 );
  19.     lastMouse = Vector3(transform.eulerAngles.x + lastMouse.x , transform.eulerAngles.y + lastMouse.y, 0);
  20.     transform.eulerAngles = lastMouse;
  21.     lastMouse =  Input.mousePosition;
  22.  
  23.         var f : float = 0.0;
  24.     var p = GetBaseInput();
  25.  
  26.     if (Input.GetKey (KeyCode.LeftShift)){
  27.  
  28.         totalRun += Time.deltaTime;
  29.         p  = p * totalRun * shiftAdd;
  30.         p.x = Mathf.Clamp(p.x, -maxShift, maxShift);
  31.         p.y = Mathf.Clamp(p.y, -maxShift, maxShift);
  32.         p.z = Mathf.Clamp(p.z, -maxShift, maxShift);
  33.         }
  34.     else{
  35.             totalRun = Mathf.Clamp(totalRun * 0.5, 1, 1000);
  36.         p = p * mainSpeed;
  37.     }
  38.  
  39.     p = p * Time.deltaTime;
  40.  
  41.     if (Input.GetKey(KeyCode.Space)){ //If player wants to move on X and Z axis only
  42.  
  43.         f = transform.position.y;
  44.         transform.Translate(p);
  45.         transform.position.y = f;
  46.     }
  47.     else{
  48.         transform.Translate( p);
  49.     }
  50. }
  51.  
  52. private function GetBaseInput() : Vector3 {
  53.  
  54.     var p_Velocity : Vector3;
  55.  
  56.     if (Input.GetKey (KeyCode.W)){
  57.         p_Velocity += Vector3(0, 0 , 1);
  58.     }
  59.  
  60.     if (Input.GetKey (KeyCode.S)){
  61.         p_Velocity += Vector3(0, 0 , -1);
  62.     }
  63.  
  64.     if (Input.GetKey (KeyCode.A)){
  65.         p_Velocity += Vector3(-1, 0 , 0);
  66.     }
  67.  
  68.     if (Input.GetKey (KeyCode.D)){
  69.         p_Velocity += Vector3(1, 0 , 0);
  70.     }
  71.  
  72.     return p_Velocity;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement