diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 8ba705acd..22a025444 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -459,17 +459,25 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl() const { FWheelPhysicsControl PhysicsWheel; - PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i); - PhysicsWheel.DampingRate = Cm2ToM2(PWheelData.mDampingRate); - PhysicsWheel.MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer); - PhysicsWheel.Radius = PWheelData.mRadius; - PhysicsWheel.MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque); - PhysicsWheel.MaxHandBrakeTorque = Cm2ToM2(PWheelData.mMaxHandBrakeTorque); + if (bPhysicsEnabled) { + PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i); - PxVehicleTireData PTireData = Vehicle4W->PVehicle->mWheelsSimData.getTireData(i); - PhysicsWheel.LatStiffMaxLoad = PTireData.mLatStiffX; - PhysicsWheel.LatStiffValue = PTireData.mLatStiffY; - PhysicsWheel.LongStiffValue = PTireData.mLongitudinalStiffnessPerUnitGravity; + PhysicsWheel.DampingRate = Cm2ToM2(PWheelData.mDampingRate); + PhysicsWheel.MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer); + PhysicsWheel.Radius = PWheelData.mRadius; + PhysicsWheel.MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque); + PhysicsWheel.MaxHandBrakeTorque = Cm2ToM2(PWheelData.mMaxHandBrakeTorque); + + PxVehicleTireData PTireData = Vehicle4W->PVehicle->mWheelsSimData.getTireData(i); + + PhysicsWheel.LatStiffMaxLoad = PTireData.mLatStiffX; + PhysicsWheel.LatStiffValue = PTireData.mLatStiffY; + PhysicsWheel.LongStiffValue = PTireData.mLongitudinalStiffnessPerUnitGravity; + } else { + if (i < LastPhysicsControl.Wheels.Num()) { + PhysicsWheel = LastPhysicsControl.Wheels[i]; + } + } PhysicsWheel.TireFriction = Vehicle4W->Wheels[i]->TireConfig->GetFrictionScale(); PhysicsWheel.Position = Vehicle4W->Wheels[i]->Location; @@ -537,17 +545,23 @@ FVehiclePhysicsControl ACarlaWheeledVehicle::GetVehiclePhysicsControl() const { FWheelPhysicsControl PhysicsWheel; - PxVehicleWheelData PWheelData = VehicleNW->PVehicle->mWheelsSimData.getWheelData(i); - PhysicsWheel.DampingRate = Cm2ToM2(PWheelData.mDampingRate); - PhysicsWheel.MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer); - PhysicsWheel.Radius = PWheelData.mRadius; - PhysicsWheel.MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque); - PhysicsWheel.MaxHandBrakeTorque = Cm2ToM2(PWheelData.mMaxHandBrakeTorque); + if (bPhysicsEnabled) { + PxVehicleWheelData PWheelData = VehicleNW->PVehicle->mWheelsSimData.getWheelData(i); + PhysicsWheel.DampingRate = Cm2ToM2(PWheelData.mDampingRate); + PhysicsWheel.MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer); + PhysicsWheel.Radius = PWheelData.mRadius; + PhysicsWheel.MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque); + PhysicsWheel.MaxHandBrakeTorque = Cm2ToM2(PWheelData.mMaxHandBrakeTorque); - PxVehicleTireData PTireData = VehicleNW->PVehicle->mWheelsSimData.getTireData(i); - PhysicsWheel.LatStiffMaxLoad = PTireData.mLatStiffX; - PhysicsWheel.LatStiffValue = PTireData.mLatStiffY; - PhysicsWheel.LongStiffValue = PTireData.mLongitudinalStiffnessPerUnitGravity; + PxVehicleTireData PTireData = VehicleNW->PVehicle->mWheelsSimData.getTireData(i); + PhysicsWheel.LatStiffMaxLoad = PTireData.mLatStiffX; + PhysicsWheel.LatStiffValue = PTireData.mLatStiffY; + PhysicsWheel.LongStiffValue = PTireData.mLongitudinalStiffnessPerUnitGravity; + } else { + if (i < LastPhysicsControl.Wheels.Num()) { + PhysicsWheel = LastPhysicsControl.Wheels[i]; + } + } PhysicsWheel.TireFriction = VehicleNW->Wheels[i]->TireConfig->GetFrictionScale(); PhysicsWheel.Position = VehicleNW->Wheels[i]->Location;