Add options for vehicle wheel suspension configuration and state
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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).
|
||||
/// </summary>
|
||||
API_FIELD() ScriptingObjectReference<Collider> Collider;
|
||||
|
||||
/// <summary>
|
||||
/// Spring damper rate of suspension unit.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="Limit(0)") float SuspensionDampingRate = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum offset for the suspension that wheel can go above resting location.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="Limit(0)") float SuspensionMaxRaise = 10.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum offset for the suspension that wheel can go below resting location.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="Limit(0)") float SuspensionMaxDrop = 10.0f;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -246,6 +261,21 @@ public:
|
||||
/// The friction experienced by the tire for the combination of tire type and surface type after accounting.
|
||||
/// </summary>
|
||||
API_FIELD() float TireFriction = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The steer angle (in degrees) of the wheel about the "up" vector accounting for input steer and toe and, if applicable, Ackermann steer correction.
|
||||
/// </summary>
|
||||
API_FIELD() float SteerAngle = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The rotation angle (in degrees) about the rolling axis for the specified wheel.
|
||||
/// </summary>
|
||||
API_FIELD() float RotationAngle = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The compression of the suspension spring. Offsets the wheel location.
|
||||
/// </summary>
|
||||
API_FIELD() float SuspensionOffset = 0.0f;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user