Skip to content

Commit

Permalink
added friction, angular drag and acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorSimona committed Jan 4, 2021
1 parent d21f355 commit dc3b7a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PhysicMaterial:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Car
dynamicFriction: 0
staticFriction: 0
dynamicFriction: 0.6
staticFriction: 0.6
bounciness: 1
frictionCombine: 0
bounceCombine: 0
bounceCombine: 2
16 changes: 14 additions & 2 deletions BottomGear/Assets/Game/Scenes/TestScenes/Vehicle.unity
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,13 @@ PrefabInstance:
propertyPath: m_Drag
value: 0
objectReference: {fileID: 0}
- target: {fileID: 865184823, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: m_Mass
value: 1000
objectReference: {fileID: 0}
- target: {fileID: 865184823, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: m_AngularDrag
value: 0
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 865184823, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: m_CollisionDetection
Expand All @@ -541,13 +545,21 @@ PrefabInstance:
propertyPath: test
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1817820544, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: maxAngle
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1817820544, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: maxSpeed
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1817820544, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: maxTorque
value: 2500
objectReference: {fileID: 0}
- target: {fileID: 1817820544, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: criticalSpeed
value: 5
value: 20
objectReference: {fileID: 0}
- target: {fileID: 1864884027688733411, guid: 75980be8169e8844595d320b13a7e456, type: 3}
propertyPath: m_Name
Expand Down
5 changes: 5 additions & 0 deletions BottomGear/Assets/Game/Scripts/Car/WheelDrive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class WheelDrive : MonoBehaviour
public float criticalSpeed = 5f;
[Tooltip("The vehicle's limit speed.")]
public float maxSpeed = 30;
[Tooltip("The vehicle's acceleration multiplier.")]
public float acceleration = 5.0f;
[Tooltip("Simulation sub-steps when the speed is above critical.")]
public int stepsBelow = 5;
[Tooltip("Simulation sub-steps when the speed is below critical.")]
Expand Down Expand Up @@ -108,6 +110,8 @@ void Update()
{
torque = 0;
}
else
rb.AddForce(transform.forward * acceleration * Input.GetAxis("Vertical"), ForceMode.Acceleration);

float handBrake = Input.GetKey(KeyCode.X) ? brakeTorque : 0;

Expand All @@ -131,6 +135,7 @@ void Update()
&& driveType != DriveType.FrontWheelDrive)
{
wheel.motorTorque = torque;

}

if (m_Wheels[i].mesh.name == "Wheel1Mesh"
Expand Down

0 comments on commit dc3b7a5

Please sign in to comment.