Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. public void VehicleMovement() {
  2.  
  3.         if (!Reverse) {
  4.  
  5.             transform.Translate(Vector3.forward * Convert.ToInt32(CurrentSpeed) / 2 * Time.deltaTime);
  6.         } else {
  7.  
  8.             transform.Translate(Vector3.back * Convert.ToInt32(CurrentSpeed) / 2 * Time.deltaTime);
  9.         }
  10.     }
  11.  
  12. public void HandleSteer() {
  13.  
  14.         if (CurrentSpeed > 0) {
  15.  
  16.             if (IsSteering == 1 && CurrentSteerAngle < MaxSteerAngle) {
  17.  
  18.                 if(!Reverse) CurrentSteerAngle += 5;
  19.                 else CurrentSteerAngle -= 5;
  20.             }
  21.  
  22.             if (IsSteering == -1 && CurrentSteerAngle > MaxSteerAngle * -1) {
  23.  
  24.                 if (!Reverse) CurrentSteerAngle -= 5;
  25.                 else CurrentSteerAngle += 5;
  26.             }
  27.  
  28.             if (IsSteering == 0) {
  29.  
  30.                 if (CurrentSteerAngle < 0) {
  31.  
  32.                     CurrentSteerAngle += 5;
  33.                 }
  34.                 else if (CurrentSteerAngle > 0) {
  35.  
  36.                     CurrentSteerAngle -= 5;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.  
  42. public void Shifter() {
  43.  
  44.         if(IsAutomatic) {
  45.  
  46.             if(CurrentGear < Gears && CurrentRPM >= GearChangeRPM && CurrentSpeed >= GearUpshiftSpeed[CurrentGear - 1]) {
  47.  
  48.                 CurrentGear ++;
  49.                 CurrentRPM -= Convert.ToInt32(Math.Ceiling(GearChangeRPM / 2.0));
  50.             }
  51.  
  52.             if(!SpeedGoingUp) {
  53.                 if(CurrentSpeed <= GearDownshiftSpeed[CurrentGear - 1] && CurrentGear > 1) {
  54.  
  55.                     CurrentGear --;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         if (Input.GetKeyDown(KeyCode.LeftControl) && CurrentGear == 1 && !Reverse) Reverse = true;
  61.         if (Input.GetKeyDown(KeyCode.LeftShift) && Reverse) Reverse = false;
  62.     }
  63.  
  64. public void HandleSpeed() {
  65.  
  66.         if (!SpeedGoingUp) {
  67.  
  68.             if (!BrakeApplied && CurrentSpeed > 0) CurrentSpeed -= .1;
  69.             else if (BrakeApplied && CurrentSpeed > 0) CurrentSpeed -= .6;
  70.  
  71.             if (Chassis != null && VehicleGForceTilt > 0) {
  72.                 Chassis.transform.Rotate(-0.25f, 0, 0);
  73.                 VehicleGForceTilt -= .25;
  74.             }
  75.  
  76.             if (CurrentSpeed < 0) CurrentSpeed = 0;
  77.  
  78.             if(CurrentRPM > 1100) {
  79.  
  80.                 CurrentRPM -= Convert.ToInt32(Math.Ceiling(10 * GearRatio[CurrentGear - 1]));
  81.             } else if(CurrentRPM < 1100) {
  82.  
  83.                 CurrentRPM = 1100;
  84.             }
  85.         } else {
  86.  
  87.             if(CurrentRPM < MaximumRPM) {
  88.  
  89.                 CurrentRPM += Convert.ToInt32(Math.Ceiling(20 * GearRatio[CurrentGear - 1]));
  90.             } else if(CurrentRPM > MaximumRPM) {
  91.  
  92.                 CurrentRPM = MaximumRPM;
  93.             }
  94.  
  95.             if (CurrentSpeed < GearMaxSpeed[CurrentGear - 1]) {
  96.  
  97.                 CurrentSpeed += .1;
  98.                
  99.                 if(Chassis != null && VehicleGForceTilt < 2) {
  100.  
  101.                     Chassis.transform.Rotate(.25f, 0, 0);
  102.                     VehicleGForceTilt += .25;
  103.                 }
  104.             }
  105.         }
  106.     }
  107.  
  108. public void VehicleControls() {
  109.  
  110.         if (Input.GetKeyDown("w")) SpeedGoingUp = true;
  111.         if (Input.GetKeyUp("w")) SpeedGoingUp = false;
  112.  
  113.         if(Input.GetKeyDown("s")) {
  114.  
  115.             BrakeApplied = true;
  116.             GUI.ToggleBrakeMsg(true);
  117.         }
  118.         if(Input.GetKeyUp("s")) {
  119.  
  120.             BrakeApplied = false;
  121.             GUI.ToggleBrakeMsg(false);
  122.         }
  123.  
  124.         if (Input.GetKeyDown("d")) { IsSteering = 1; SteerRotation = 1; };
  125.         if (Input.GetKeyDown("a")) { IsSteering = -1; SteerRotation = -1; }
  126.         if (Input.GetKeyUp("d") || Input.GetKeyUp("a")) { IsSteering = 0; SteerRotation = 0; }
  127.  
  128.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement