setting tire config during begin play

This commit is contained in:
Manish 2019-04-15 13:02:36 +02:00
parent 627c351e85
commit 6b65e5833a
2 changed files with 39 additions and 7 deletions

View File

@ -29,6 +29,33 @@ ACarlaWheeledVehicle::ACarlaWheeledVehicle(const FObjectInitializer& ObjectIniti
ACarlaWheeledVehicle::~ACarlaWheeledVehicle() {}
void ACarlaWheeledVehicle::BeginPlay()
{
Super::BeginPlay();
// Setup Tire Configs
UWheeledVehicleMovementComponent4W *Vehicle4W = CastChecked<UWheeledVehicleMovementComponent4W>(GetVehicleMovementComponent());
// Wheels Setup
TArray<FWheelSetup> NewWheelSetups = Vehicle4W->WheelSetups;
for (int32 i = 0; i < Vehicle4W->WheelSetups.Num(); ++i)
{
UVehicleWheel *Wheel = NewWheelSetups[i].WheelClass.GetDefaultObject();
// Assigning new tire config
float Friction = Wheel->TireConfig->GetFrictionScale();
Wheel->TireConfig = NewObject<UTireConfig>();
// Setting a new value to friction
Wheel->TireConfig->SetFrictionScale(Friction);
}
Vehicle4W->WheelSetups = NewWheelSetups;
Vehicle4W->VehicleSetupTag++;
}
// =============================================================================
// -- Get functions ------------------------------------------------------------
// =============================================================================
@ -224,17 +251,13 @@ void ACarlaWheeledVehicle::ApplyVehiclePhysicsControl(const FVehiclePhysicsContr
Wheel->DampingRate = PhysicsControl.Wheels[i].DampingRate;
Wheel->SteerAngle = PhysicsControl.Wheels[i].SteerAngle;
NewWheelSetups[i].bDisableSteering = PhysicsControl.Wheels[i].bDisableSteering;
// Assigning new tire config
Wheel->TireConfig = NewObject<UTireConfig>();
// Setting a new value to friction
Wheel->TireConfig->SetFrictionScale(PhysicsControl.Wheels[i].TireFriction);
NewWheelSetups[i].bDisableSteering = PhysicsControl.Wheels[i].bDisableSteering;
}
Vehicle4W->WheelSetups = NewWheelSetups;
Vehicle4W->RecreatePhysicsState();
Vehicle4W->VehicleSetupTag++;
}

View File

@ -172,6 +172,15 @@ public:
SetHandbrakeInput(false);
}
/// @}
// ===========================================================================
/// @name Overriden from AActor
// ===========================================================================
/// @{
protected:
virtual void BeginPlay() override;
private:
/// Current state of the vehicle controller (for debugging purposes).