Hi,
If you have many standing still vehicles on the level it is better do not calculate DragForce too often.
In my case I had 40+ vehicles and they consumes 6 ms of game time
I think this function should be changed to something like that:
void UWheeledVehicleMovementComponent::UpdateDrag(float DeltaTime)
{
if (PVehicle && UpdatedComponent)
{
float ForwardSpeed = GetForwardSpeed();
if (FMath::Abs(ForwardSpeed) > 1.f)
{
FVector GlobalForwardVector = UpdatedComponent->GetForwardVector();
FVector DragVector = -GlobalForwardVector;
float SpeedSquared = ForwardSpeed * ForwardSpeed;
float ChassisDragArea = ChassisHeight * ChassisWidth;
float AirDensity = 1.25 / (100 * 100 * 100); //kg/cm^3
float DragMag = 0.5f * AirDensity * SpeedSquared * DragCoefficient * ChassisDragArea;
DebugDragMagnitude = DragMag;
DragVector *= DragMag;
FBodyInstance * BodyInstance = UpdatedComponent->GetBodyInstance();
BodyInstance->AddForce(DragVector, false);
}
}
}
Regards
Pierdek