Skip to content

Commit 6875c23

Browse files
committed
veichle simulation refactored
1 parent 2348aac commit 6875c23

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

Assets/Source/Veichle/VeichleSimulation.cs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class VeichleSimulation : MonoBehaviour, IVeichleControls
77
{
88

99
public float accelSpeed;
10-
public float brakeValue;
10+
public float maxBrakeValue;
1111
public float maxTurnAngle;
1212
public float turnSpeed;
1313

@@ -20,7 +20,6 @@ public class VeichleSimulation : MonoBehaviour, IVeichleControls
2020
Transform[] anteriorWheels;
2121

2222
float accel;
23-
float brake;
2423
float angle;
2524

2625
// Use this for initialization
@@ -36,43 +35,22 @@ void Start ()
3635

3736
public void Accelerate(float accelValue)
3837
{
39-
4038
if (accelValue > 0)
4139
{
42-
if (wheelsColliders[0].motorTorque <= 0)
43-
{
44-
accel = -accelValue * accelSpeed;
45-
brake = 0;
46-
}
47-
else
48-
{
49-
accel = 0;
50-
brake = brakeValue;
51-
}
40+
accel = -accelValue * accelSpeed;
5241
}
5342
else if(accelValue < 0)
5443
{
55-
if (wheelsColliders[0].motorTorque >= 0)
56-
{
57-
accel = -accelValue * accelSpeed * 0.5f;
58-
brake = 0;
59-
}
60-
else
61-
{
62-
brake = brakeValue;
63-
accel = 0;
64-
}
44+
accel = -accelValue * accelSpeed * 0.5f;
6545
}
6646
else
6747
{
68-
brake = 0;
6948
accel = 0;
7049
}
7150

7251
foreach (WheelCollider wheel in wheelsColliders)
7352
{
7453
wheel.motorTorque = accel;
75-
wheel.brakeTorque = brake;
7654
}
7755

7856
}
@@ -109,12 +87,16 @@ public void Steer(float steerValue)
10987

11088
public void Brake(bool isBraking)
11189
{
112-
if(isBraking)
90+
float currentBrakeValue = 0;
91+
92+
if (isBraking)
11393
{
114-
foreach (WheelCollider wheel in wheelsColliders)
115-
{
116-
wheel.brakeTorque = brakeValue;
117-
}
94+
currentBrakeValue = maxBrakeValue;
95+
}
96+
97+
foreach (WheelCollider wheel in wheelsColliders)
98+
{
99+
wheel.brakeTorque = currentBrakeValue;
118100
}
119101
}
120102

0 commit comments

Comments
 (0)