probably broken car controller

This commit is contained in:
2024-04-05 12:18:11 +02:00
parent 28562de791
commit 7dfa783aac
2 changed files with 70 additions and 5 deletions

View File

@@ -202,7 +202,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 218143925}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a23c7d66d3ff94847a946cf7b30ca1b7, type: 3}
m_Name:
@@ -245,6 +245,22 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1857703685905104433, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2883785401448142367, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_ForwardFriction.m_Stiffness
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2883785401448142367, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_SidewaysFriction.m_Stiffness
value: 2
objectReference: {fileID: 0}
- target: {fileID: 3239213433477781764, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_Drag
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 5420764024659664985, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_LocalPosition.x
value: 9
@@ -289,10 +305,21 @@ PrefabInstance:
propertyPath: m_Name
value: Hotrod
objectReference: {fileID: 0}
- target: {fileID: 6429322875164058677, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_ForwardFriction.m_Stiffness
value: 2
objectReference: {fileID: 0}
- target: {fileID: 6429322875164058677, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
propertyPath: m_SidewaysFriction.m_Stiffness
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 5711380006811689493, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
insertIndex: -1
addedObject: {fileID: 749736917}
m_SourcePrefab: {fileID: 100100000, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
--- !u!1001 &300876409
PrefabInstance:
@@ -703,6 +730,29 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 450060be716600a46927ba00fb04135b, type: 3}
--- !u!1 &749736913 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5711380006811689493, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
m_PrefabInstance: {fileID: 293910239}
m_PrefabAsset: {fileID: 0}
--- !u!114 &749736917
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 749736913}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 58d3a2623a4164b4bb25683edc176b03, type: 3}
m_Name:
m_EditorClassIdentifier:
motorTorque: 5000
brakeTorque: 20000
maxSpeed: 1000
steeringRange: 60
steeringRangeAtMaxSpeed: 35
autoBrake: 5000
--- !u!1001 &760601908
PrefabInstance:
m_ObjectHideFlags: 0

View File

@@ -10,6 +10,8 @@ public class carcontrolv2 : MonoBehaviour
public float steeringRange = 30;
public float steeringRangeAtMaxSpeed = 10;
public float autoBrake;
WheelControl[] wheels;
Rigidbody rigidBody;
@@ -50,6 +52,12 @@ public class carcontrolv2 : MonoBehaviour
// as the car's velocity
bool isAccelerating = Mathf.Sign(vInput) == Mathf.Sign(forwardSpeed);
bool isStopping = vInput == 0; // range
bool isBraking = vInput < 0 && forwardSpeed > 0;
Debug.Log(vInput);
foreach (var wheel in wheels)
{
// Apply steering to Wheel colliders that have "Steerable" enabled
@@ -67,12 +75,19 @@ public class carcontrolv2 : MonoBehaviour
}
wheel.WheelCollider.brakeTorque = 0;
}
else
if (isBraking)
{
wheel.WheelCollider.brakeTorque = Mathf.Abs(vInput) * brakeTorque;
//wheel.WheelCollider.motorTorque = 0;
}
if (isStopping)
{
// If the user is trying to go in the opposite direction
// apply brakes to all wheels
wheel.WheelCollider.brakeTorque = Mathf.Abs(vInput) * brakeTorque;
wheel.WheelCollider.motorTorque = 0;
wheel.WheelCollider.brakeTorque = Mathf.Abs(vInput) * brakeTorque + autoBrake;
// wheel.WheelCollider.motorTorque = 0;
}
}
}