@@ -156,7 +156,8 @@ TrackedVehicleController::TrackedVehicleController(const TrackedVehicleControlle
bool TrackedVehicleController::AllowSleep() const
{
return mForwardInput == 0.0f // No user input
- && mEngine.GetCurrentRPM() <= 1.01f * mEngine.mMinRPM; // Engine is idling
+ && mTransmission.AllowSleep() // Transmission is not shifting
+ && mEngine.AllowSleep(); // Engine is idling
}
void TrackedVehicleController::PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem)
@@ -79,6 +79,9 @@ public:
void DrawRPM(DebugRenderer *inRenderer, RVec3Arg inPosition, Vec3Arg inForward, Vec3Arg inUp, float inSize, float inShiftDownRPM, float inShiftUpRPM) const;
#endif // JPH_DEBUG_RENDERER
+ /// If the engine is idle we allow the vehicle to sleep
+ bool AllowSleep() const { return mCurrentRPM <= 1.01f * mMinRPM; }
+
/// Saving state for replay
void SaveState(StateRecorder &inStream) const;
void RestoreState(StateRecorder &inStream);
@@ -69,6 +69,9 @@ public:
/// Return the transmission ratio based on the current gear (ratio between engine and differential)
float GetCurrentRatio() const;
+ /// Only allow sleeping when the transmission is idle
+ bool AllowSleep() const { return mGearSwitchTimeLeft <= 0.0f && mClutchReleaseTimeLeft <= 0.0f && mGearSwitchLatencyTimeLeft <= 0.0f; }
@@ -224,7 +224,8 @@ float WheeledVehicleController::GetWheelSpeedAtClutch() const
bool WheeledVehicleController::AllowSleep() const
void WheeledVehicleController::PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem)