From 2242614d4a568b96620c3060fffb7b411b2dad92 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Tue, 1 Aug 2023 02:22:15 -0700 Subject: [PATCH] vehicle: Use StiffnessAndDamping for spring Removes my todo here, and improves vehicles a lot. --- vphysics_jolt/vjolt_controller_vehicle.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/vphysics_jolt/vjolt_controller_vehicle.cpp b/vphysics_jolt/vjolt_controller_vehicle.cpp index f0fe7c1..6c2cd5b 100644 --- a/vphysics_jolt/vjolt_controller_vehicle.cpp +++ b/vphysics_jolt/vjolt_controller_vehicle.cpp @@ -420,17 +420,11 @@ void JoltPhysicsVehicleController::CreateWheel( JPH::VehicleConstraintSettings & wheelSettings->mInertia = 0.5f * axle.wheels.mass * ( wheelSettings->mRadius * wheelSettings->mRadius ); wheelSettings->mSuspensionMinLength = 0; wheelSettings->mSuspensionMaxLength = additionalLength; - wheelSettings->mSuspensionSpring.mMode = JPH::ESpringMode::FrequencyAndDamping; - // Josh: - // so to go from K (Spring Constant) -> freq we do - // sqrtf( K / Mass ) / ( 2.0f * PI ) - // but it seems like it already has mass divided in Source so... - // sqrtf( K ) / ( 2.0f * PI ) - // Josh: I don't know why but it looks and feels really wrong without this: - // TODO(Josh): Investigate more later, doesn't make much sense. - // May be related to mass of wheel or something. - wheelSettings->mSuspensionSpring.mFrequency = sqrtf( axle.suspension.springConstant ) / ( 2.0f * M_PI_F ) * M_PI_F; - wheelSettings->mSuspensionSpring.mDamping = axle.suspension.springDamping; + wheelSettings->mSuspensionSpring.mMode = JPH::ESpringMode::StiffnessAndDamping; + // Source has these divided by the mass of the vehicle for some reason. + // Convert these to a stiffness of k, in N/m... + wheelSettings->mSuspensionSpring.mStiffness = axle.suspension.springConstant * m_pCarBodyObject->GetMass(); + wheelSettings->mSuspensionSpring.mDamping = axle.suspension.springDamping * m_pCarBodyObject->GetMass(); if ( axle.wheels.frictionScale ) { wheelSettings->mLateralFriction.AddPoint( 1.0f, axle.wheels.frictionScale );