diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index 0fe53f570..388aa1f21 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -303,12 +303,11 @@ void WheeledVehicle::Setup() PxVehicleSuspensionData suspensionData; const float suspensionFrequency = 7.0f; - const float suspensionDampingRatio = 1.0f; - suspensionData.mMaxCompression = 10.0f; - suspensionData.mMaxDroop = 10.0f; + suspensionData.mMaxCompression = wheel.SuspensionMaxRaise; + suspensionData.mMaxDroop = wheel.SuspensionMaxDrop; suspensionData.mSprungMass = sprungMasses[i]; suspensionData.mSpringStrength = Math::Square(suspensionFrequency) * suspensionData.mSprungMass; - suspensionData.mSpringDamperRate = suspensionDampingRatio * 2.0f * Math::Sqrt(suspensionData.mSpringStrength * suspensionData.mSprungMass); + suspensionData.mSpringDamperRate = wheel.SuspensionDampingRate * 2.0f * Math::Sqrt(suspensionData.mSpringStrength * suspensionData.mSprungMass); PxVehicleTireData tire; tire.mType = 0; diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index 1941038bf..a6a1708ad 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -213,6 +213,21 @@ public: /// Collider that represents the wheel shape and it's placement. Has to be attached as a child to the vehicle. Triangle mesh collider is not supported (use convex mesh or basic shapes). /// API_FIELD() ScriptingObjectReference Collider; + + /// + /// Spring damper rate of suspension unit. + /// + API_FIELD(Attributes="Limit(0)") float SuspensionDampingRate = 1.0f; + + /// + /// The maximum offset for the suspension that wheel can go above resting location. + /// + API_FIELD(Attributes="Limit(0)") float SuspensionMaxRaise = 10.0f; + + /// + /// The maximum offset for the suspension that wheel can go below resting location. + /// + API_FIELD(Attributes="Limit(0)") float SuspensionMaxDrop = 10.0f; }; /// @@ -246,6 +261,21 @@ public: /// The friction experienced by the tire for the combination of tire type and surface type after accounting. /// API_FIELD() float TireFriction = 0.0f; + + /// + /// The steer angle (in degrees) of the wheel about the "up" vector accounting for input steer and toe and, if applicable, Ackermann steer correction. + /// + API_FIELD() float SteerAngle = 0.0f; + + /// + /// The rotation angle (in degrees) about the rolling axis for the specified wheel. + /// + API_FIELD() float RotationAngle = 0.0f; + + /// + /// The compression of the suspension spring. Offsets the wheel location. + /// + API_FIELD() float SuspensionOffset = 0.0f; }; private: diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index bdee2fdc2..8066f404d 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -845,10 +845,12 @@ void Physics::CollectResults() state.TireContactPoint = P2C(perWheel.tireContactPoint); state.TireContactNormal = P2C(perWheel.tireContactNormal); state.TireFriction = perWheel.tireFriction; + state.SteerAngle = RadiansToDegrees * perWheel.steerAngle; + state.RotationAngle = -RadiansToDegrees * drive->mWheelsDynData.getWheelRotationAngle(j); + const float suspensionOffsetDelta = perWheel.suspJounce - state.SuspensionOffset; + state.SuspensionOffset = perWheel.suspJounce; - const float wheelRotationAngle = -RadiansToDegrees * drive->mWheelsDynData.getWheelRotationAngle(j); - const float wheelSteerAngle = RadiansToDegrees * perWheel.steerAngle; - wheelData.Collider->SetLocalOrientation(Quaternion::Euler(0, wheelSteerAngle, wheelRotationAngle) * wheelData.LocalOrientation); + wheelData.Collider->SetLocalOrientation(Quaternion::Euler(0, state.SteerAngle, state.RotationAngle) * wheelData.LocalOrientation); } } }