Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     updateFPSControls(transform) {
  3.  
  4.         if (Game.Input.Key.rightArrow.down) {
  5.             this.moving.right = true;
  6.             this.moving.left = false;
  7.             this.moving.pressedX = true;
  8.             Game.camera.rigidbody.acceleration.x = this.accelerationRate;
  9.  
  10.         }
  11.        
  12.         else if (Game.Input.Key.leftArrow.down) {
  13.             this.moving.left = true;
  14.             this.moving.right = false;
  15.             this.moving.pressedX = true;
  16.             Game.camera.rigidbody.acceleration.x = -this.accelerationRate;
  17.         }
  18.         else {
  19.             this.moving.pressedX = false;
  20.         }
  21.        
  22.        
  23.         if (Game.Input.Key.upArrow.down) {
  24.             this.moving.forward = true;
  25.             this.moving.back = false;
  26.             this.moving.pressedZ = true;
  27.             Game.camera.rigidbody.acceleration.z = -this.accelerationRate;
  28.  
  29.         }
  30.        
  31.         else if (Game.Input.Key.downArrow.down) {
  32.             this.moving.back = true;
  33.             this.moving.forward = false;
  34.             this.moving.pressedZ = true;
  35.             Game.camera.rigidbody.acceleration.z = this.accelerationRate;          
  36.         }
  37.        
  38.         else {
  39.             this.moving.pressedZ = false;
  40.         }
  41.    
  42.  
  43.     }
  44.  
  45.     updateFPSMovement (transform) {
  46.  
  47.         if (this.moving.pressedZ) {
  48.             // Moving Forward
  49.             if (this.moving.forward) {
  50.                 this.velocity.z += this.acceleration.z;
  51.        
  52.                 if (this.velocity.z <= -this.maxVelocity.z) {
  53.                     this.velocity.z = -this.maxVelocity.z;
  54.                 }
  55.             }
  56.  
  57.             // Moving Forward
  58.             if (this.moving.back) {
  59.                 this.velocity.z += this.acceleration.z;
  60.        
  61.                 if (this.velocity.z >= this.maxVelocity.z) {
  62.                     this.velocity.z = this.maxVelocity.z;
  63.                 }
  64.             }
  65.         }
  66.         else {
  67.             if (this.moving.forward) {
  68.                     if (this.velocity.z < 0) {
  69.                         this.velocity.z -= this.acceleration.z;
  70.  
  71.                         // Reached Desintation
  72.                         if (this.velocity.z >= 0) {
  73.                             this.velocity.z = 0;
  74.                             this.moving.forward = false;
  75.                         }
  76.                     }
  77.                     else {
  78.                         this.velocity.z += this.acceleration.z;
  79.                        
  80.                         // Reaached Destination
  81.                         if (this.velocity.z <= 0) {
  82.                             this.velocity.z = 0;
  83.                             this.moving.forward = false;
  84.                         }
  85.                     }
  86.                 }
  87.                
  88.                 if (this.moving.back) {
  89.                     if (this.velocity.z > 0) {
  90.                         this.velocity.z -= this.acceleration.z;
  91.                        
  92.                         // Reached Desintation
  93.                         if (this.velocity.z <= 0) {
  94.                             this.velocity.z = 0;
  95.                             this.moving.back = false;
  96.                         }
  97.                     }
  98.                     else {
  99.                         this.velocity.z += this.acceleration.z;
  100.                        
  101.                         // Reaached Destination
  102.                         if (this.velocity.z >= 0) {
  103.                             this.velocity.z = 0;
  104.                             this.moving.back = false;
  105.                         }
  106.                     }
  107.                 }
  108.         }
  109.  
  110.         if (this.moving.pressedX) {
  111.  
  112.             // Moving Right
  113.             if (this.moving.right) {
  114.                
  115.                 this.velocity.x += this.acceleration.x;
  116.                 if (this.velocity.x >= this.maxVelocity.x) {
  117.                     this.velocity.x = this.maxVelocity.x;
  118.                 }
  119.             }
  120.             // Moving Left
  121.             if (this.moving.left) {
  122.                 this.velocity.x  += this.acceleration.x;
  123.                 if (this.velocity.x <= -this.maxVelocity.x) {
  124.                     this.velocity.x = -this.maxVelocity.x;
  125.                 }
  126.  
  127.             }
  128.  
  129.         }
  130.  
  131.         // Not pressed
  132.         else {
  133.  
  134.             if (this.moving.right) {
  135.  
  136.                 if (this.velocity.x < 0) {
  137.                     this.velocity.x += this.acceleration.x;
  138.                    
  139.                     // Reached Destination.
  140.                     if (this.velocity.x >= 0) {
  141.                         this.velocity.x = 0;
  142.                         this.moving.right = false;
  143.                     }
  144.                 }
  145.                 else {
  146.                     this.velocity.x -= this.acceleration.x;
  147.  
  148.                     if (this.velocity.x <= 0) {
  149.                         this.velocity.x = 0;
  150.                         this.moving.right = false;
  151.                     }
  152.                 }
  153.             }
  154.  
  155.             if (this.moving.left) {
  156.                 if (this.velocity.x < 0) {
  157.                     this.velocity.x -= this.acceleration.x;
  158.  
  159.                     // Reached Desintation
  160.                     if (this.velocity.x >= 0) {
  161.                         this.velocity.x = 0;
  162.                         this.moving.left = false;
  163.                     }
  164.                 }
  165.                 else {
  166.                     this.velocity.x += this.acceleration.x;
  167.  
  168.                     // Reaached Destination
  169.                     if (this.velocity.x <= 0) {
  170.                         this.velocity.x = 0;
  171.                         this.moving.left = false;
  172.                     }
  173.                 }
  174.             }
  175.         }
  176.  
  177.  
  178.         transform.position.x += this.velocity.x * Game.Time.step;
  179.         transform.position.y += this.velocity.y * Game.Time.step;
  180.         transform.position.z += this.velocity.z * Game.Time.step;
  181.  
  182.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement