8 #include "Components/BoxComponent.h" 9 #include "Engine/CollisionProfile.h" 11 #include "Rendering/SkeletalMeshRenderData.h" 12 #include "UObject/UObjectGlobals.h" 13 #include "DrawDebugHelpers.h" 14 #include "Kismet/KismetSystemLibrary.h" 16 #include "PhysXPublic.h" 17 #include "PhysXVehicleManager.h" 18 #include "TireConfig.h" 19 #include "VehicleWheel.h" 36 Super(ObjectInitializer)
38 VehicleBounds = CreateDefaultSubobject<UBoxComponent>(TEXT(
"VehicleBounds"));
41 VehicleBounds->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
43 VelocityControl = CreateDefaultSubobject<UVehicleVelocityControl>(TEXT(
"VelocityControl"));
46 GetVehicleMovementComponent()->bReverseAsBrake =
false;
47 BaseMovementComponent = CreateDefaultSubobject<UBaseCarlaMovementComponent>(TEXT(
"BaseMovementComponent"));
55 #ifdef WHEEL_SWEEP_ENABLED 71 UE_LOG(LogCarla, Warning, TEXT(
"Error: Sweep for wheel collision is not available. \ 72 Make sure you have installed the required patch.") );
81 #ifdef WHEEL_SWEEP_ENABLED 92 UE_LOG(LogCarla, Warning, TEXT(
"Error: Sweep for wheel collision is not available. \ 93 Make sure you have installed the required patch.") );
105 FTransform ActorInverseTransform = GetActorTransform().Inverse();
111 UPhysicsConstraintComponent* ConstraintComponent =
112 Cast<UPhysicsConstraintComponent>(GetDefaultSubobjectByName(ComponentName));
113 if (ConstraintComponent)
116 GetDefaultSubobjectByName(ConstraintComponent->ComponentName1.ComponentName));
119 UE_LOG(LogCarla, Warning, TEXT(
"Door name: %s"), *(DoorComponent->GetName()));
120 FTransform ComponentWorldTransform = DoorComponent->GetComponentTransform();
121 FTransform RelativeTransform = ComponentWorldTransform * ActorInverseTransform;
125 ConstraintComponent->TermComponentConstraint();
129 UE_LOG(LogCarla, Error, TEXT(
"Missing component for constraint: %s"), *(ConstraintComponent->GetName()));
137 TArray<UPhysicsConstraintComponent*> Constraints;
138 GetComponents(Constraints);
139 for (UPhysicsConstraintComponent* Constraint : Constraints)
144 GetDefaultSubobjectByName(Constraint->ComponentName1.ComponentName));
146 GetDefaultSubobjectByName(Constraint->ComponentName2.ComponentName));
147 if (CollisionDisabledComponent1)
151 if (CollisionDisabledComponent2)
158 float FrictionScale = 3.5f;
160 UWheeledVehicleMovementComponent* MovementComponent = GetVehicleMovementComponent();
162 if (MovementComponent)
164 check(MovementComponent !=
nullptr);
169 TArray<float> OriginalFrictions;
170 OriginalFrictions.Init(FrictionScale, MovementComponent->Wheels.Num());
175 TArray<AActor *> OverlapActors;
176 GetOverlappingActors(OverlapActors, AFrictionTrigger::StaticClass());
177 for (
const auto &
Actor : OverlapActors)
182 FrictionScale = FrictionTrigger->
Friction;
187 TArray<FWheelSetup> NewWheelSetups = MovementComponent->WheelSetups;
188 for (
const auto &WheelSetup : NewWheelSetups)
190 UVehicleWheel *Wheel = WheelSetup.WheelClass.GetDefaultObject();
191 check(Wheel !=
nullptr);
194 MovementComponent->WheelSetups = NewWheelSetups;
214 const FTransform GlobalTransform = GetActorTransform();
216 FBox
Box = FBox(-Vec, Vec);
217 const FTransform NonScaledTransform(GlobalTransform.GetRotation(), GlobalTransform.GetLocation(), {1.0f, 1.0f, 1.0f});
242 const FQuat&
Rotation = GetActorQuat();
243 DrawDebugBox(GetWorld(), Center, Extent, Rotation, FColor::Magenta,
false, 0.0f, 0, 5.0f);
261 const FTransform& CompToWorldTransform = RootComponent->GetComponentTransform();
262 const FRotator
Rotation = CompToWorldTransform.GetRotation().Rotator();
263 const FVector Translation = CompToWorldTransform.GetLocation();
264 const FVector Scale = CompToWorldTransform.GetScale3D();
267 BoundingBox.
Origin -= Translation;
268 BoundingBox.
Origin = Rotation.UnrotateVector(BoundingBox.
Origin);
269 BoundingBox.
Origin /= Scale;
273 Transform.SetTranslation(BoundingBox.
Origin);
309 const auto &Wheels = GetVehicleMovementComponent()->Wheels;
310 check(Wheels.Num() > 0);
311 const auto *FrontWheel = Wheels[0];
312 check(FrontWheel !=
nullptr);
313 return FrontWheel->SteerAngle;
343 Control.
Steer = Value;
350 Control.
Brake = Value;
371 UWheeledVehicleMovementComponent* Movement = GetVehicleMovement();
372 TArray<float> WheelsFrictionScale;
375 check(Movement !=
nullptr);
377 for (
auto &Wheel : Movement->Wheels)
379 WheelsFrictionScale.Add(Wheel->TireConfig->GetFrictionScale());
382 return WheelsFrictionScale;
388 UWheeledVehicleMovementComponent* Movement = GetVehicleMovement();
391 check(Movement !=
nullptr);
392 check(Movement->Wheels.Num() == WheelsFrictionScale.Num());
394 for (int32 i = 0; i < Movement->Wheels.Num(); ++i)
396 Movement->Wheels[i]->TireConfig->SetFrictionScale(WheelsFrictionScale[i]);
406 UWheeledVehicleMovementComponent4W *Vehicle4W = Cast<UWheeledVehicleMovementComponent4W>(
407 GetVehicleMovement());
408 check(Vehicle4W !=
nullptr);
411 PhysicsControl.
TorqueCurve = Vehicle4W->EngineSetup.TorqueCurve.EditorCurveData;
412 PhysicsControl.
MaxRPM = Vehicle4W->EngineSetup.MaxRPM;
413 PhysicsControl.
MOI = Vehicle4W->EngineSetup.MOI;
416 Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchEngaged;
418 Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchDisengaged;
421 PhysicsControl.
bUseGearAutoBox = Vehicle4W->TransmissionSetup.bUseGearAutoBox;
422 PhysicsControl.
GearSwitchTime = Vehicle4W->TransmissionSetup.GearSwitchTime;
423 PhysicsControl.
ClutchStrength = Vehicle4W->TransmissionSetup.ClutchStrength;
424 PhysicsControl.
FinalRatio = Vehicle4W->TransmissionSetup.FinalRatio;
426 TArray<FGearPhysicsControl> ForwardGears;
428 for (
const auto &Gear : Vehicle4W->TransmissionSetup.ForwardGears)
432 GearPhysicsControl.
Ratio = Gear.Ratio;
433 GearPhysicsControl.
UpRatio = Gear.UpRatio;
434 GearPhysicsControl.
DownRatio = Gear.DownRatio;
436 ForwardGears.Add(GearPhysicsControl);
442 PhysicsControl.
Mass = Vehicle4W->Mass;
447 UPrimitiveComponent *UpdatedPrimitive = Cast<UPrimitiveComponent>(Vehicle4W->UpdatedComponent);
448 check(UpdatedPrimitive !=
nullptr);
450 PhysicsControl.
CenterOfMass = UpdatedPrimitive->BodyInstance.COMNudge;
453 PhysicsControl.
SteeringCurve = Vehicle4W->SteeringCurve.EditorCurveData;
456 TArray<FWheelPhysicsControl> Wheels;
458 for (int32 i = 0; i < Vehicle4W->WheelSetups.Num(); ++i)
462 PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i);
463 PhysicsWheel.
DampingRate = Cm2ToM2(PWheelData.mDampingRate);
464 PhysicsWheel.
MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer);
465 PhysicsWheel.
Radius = PWheelData.mRadius;
466 PhysicsWheel.
MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque);
469 PxVehicleTireData PTireData = Vehicle4W->PVehicle->mWheelsSimData.getTireData(i);
472 PhysicsWheel.
LongStiffValue = PTireData.mLongitudinalStiffnessPerUnitGravity;
474 PhysicsWheel.
TireFriction = Vehicle4W->Wheels[i]->TireConfig->GetFrictionScale();
475 PhysicsWheel.
Position = Vehicle4W->Wheels[i]->Location;
477 Wheels.Add(PhysicsWheel);
480 PhysicsControl.
Wheels = Wheels;
483 UWheeledVehicleMovementComponentNW *VehicleNW = Cast<UWheeledVehicleMovementComponentNW>(
484 GetVehicleMovement());
486 check(VehicleNW !=
nullptr);
489 PhysicsControl.
TorqueCurve = VehicleNW->EngineSetup.TorqueCurve.EditorCurveData;
490 PhysicsControl.
MaxRPM = VehicleNW->EngineSetup.MaxRPM;
491 PhysicsControl.
MOI = VehicleNW->EngineSetup.MOI;
494 VehicleNW->EngineSetup.DampingRateZeroThrottleClutchEngaged;
496 VehicleNW->EngineSetup.DampingRateZeroThrottleClutchDisengaged;
499 PhysicsControl.
bUseGearAutoBox = VehicleNW->TransmissionSetup.bUseGearAutoBox;
500 PhysicsControl.
GearSwitchTime = VehicleNW->TransmissionSetup.GearSwitchTime;
501 PhysicsControl.
ClutchStrength = VehicleNW->TransmissionSetup.ClutchStrength;
502 PhysicsControl.
FinalRatio = VehicleNW->TransmissionSetup.FinalRatio;
504 TArray<FGearPhysicsControl> ForwardGears;
506 for (
const auto &Gear : VehicleNW->TransmissionSetup.ForwardGears)
510 GearPhysicsControl.
Ratio = Gear.Ratio;
511 GearPhysicsControl.
UpRatio = Gear.UpRatio;
512 GearPhysicsControl.
DownRatio = Gear.DownRatio;
514 ForwardGears.Add(GearPhysicsControl);
520 PhysicsControl.
Mass = VehicleNW->Mass;
525 UPrimitiveComponent *UpdatedPrimitive = Cast<UPrimitiveComponent>(VehicleNW->UpdatedComponent);
526 check(UpdatedPrimitive !=
nullptr);
528 PhysicsControl.
CenterOfMass = UpdatedPrimitive->BodyInstance.COMNudge;
531 PhysicsControl.
SteeringCurve = VehicleNW->SteeringCurve.EditorCurveData;
534 TArray<FWheelPhysicsControl> Wheels;
536 for (int32 i = 0; i < VehicleNW->WheelSetups.Num(); ++i)
540 PxVehicleWheelData PWheelData = VehicleNW->PVehicle->mWheelsSimData.getWheelData(i);
541 PhysicsWheel.
DampingRate = Cm2ToM2(PWheelData.mDampingRate);
542 PhysicsWheel.
MaxSteerAngle = FMath::RadiansToDegrees(PWheelData.mMaxSteer);
543 PhysicsWheel.
Radius = PWheelData.mRadius;
544 PhysicsWheel.
MaxBrakeTorque = Cm2ToM2(PWheelData.mMaxBrakeTorque);
547 PxVehicleTireData PTireData = VehicleNW->PVehicle->mWheelsSimData.getTireData(i);
550 PhysicsWheel.
LongStiffValue = PTireData.mLongitudinalStiffnessPerUnitGravity;
552 PhysicsWheel.
TireFriction = VehicleNW->Wheels[i]->TireConfig->GetFrictionScale();
553 PhysicsWheel.
Position = VehicleNW->Wheels[i]->Location;
555 Wheels.Add(PhysicsWheel);
558 PhysicsControl.
Wheels = Wheels;
578 UWheeledVehicleMovementComponent4W *Vehicle4W = Cast<UWheeledVehicleMovementComponent4W>(
579 GetVehicleMovement());
580 check(Vehicle4W !=
nullptr);
585 Vehicle4W->EngineSetup.TorqueCurve.EditorCurveData = PhysicsControl.
TorqueCurve;
586 Vehicle4W->EngineSetup.MaxRPM = PhysicsControl.
MaxRPM;
588 Vehicle4W->EngineSetup.MOI = PhysicsControl.
MOI;
591 Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchEngaged =
593 Vehicle4W->EngineSetup.DampingRateZeroThrottleClutchDisengaged =
597 Vehicle4W->TransmissionSetup.bUseGearAutoBox = PhysicsControl.
bUseGearAutoBox;
598 Vehicle4W->TransmissionSetup.GearSwitchTime = PhysicsControl.
GearSwitchTime;
599 Vehicle4W->TransmissionSetup.ClutchStrength = PhysicsControl.
ClutchStrength;
600 Vehicle4W->TransmissionSetup.FinalRatio = PhysicsControl.
FinalRatio;
602 TArray<FVehicleGearData> ForwardGears;
606 FVehicleGearData GearData;
608 GearData.Ratio = Gear.Ratio;
609 GearData.UpRatio = Gear.UpRatio;
610 GearData.DownRatio = Gear.DownRatio;
612 ForwardGears.Add(GearData);
615 Vehicle4W->TransmissionSetup.ForwardGears = ForwardGears;
618 Vehicle4W->Mass = PhysicsControl.
Mass;
622 UPrimitiveComponent *UpdatedPrimitive = Cast<UPrimitiveComponent>(Vehicle4W->UpdatedComponent);
623 check(UpdatedPrimitive !=
nullptr);
625 UpdatedPrimitive->BodyInstance.COMNudge = PhysicsControl.
CenterOfMass;
628 Vehicle4W->SteeringCurve.EditorCurveData = PhysicsControl.
SteeringCurve;
631 const int PhysicsWheelsNum = PhysicsControl.
Wheels.Num();
632 if (PhysicsWheelsNum != 4)
634 UE_LOG(LogCarla, Error, TEXT(
"Number of WheelPhysicsControl is not 4."));
641 TArray<FWheelSetup> NewWheelSetups = Vehicle4W->WheelSetups;
643 for (int32 i = 0; i < PhysicsWheelsNum; ++i)
645 UVehicleWheel *Wheel = NewWheelSetups[i].WheelClass.GetDefaultObject();
646 check(Wheel !=
nullptr);
649 Wheel->TireConfig = DuplicateObject<UTireConfig>(Wheel->TireConfig,
nullptr);
652 Wheel->TireConfig->SetFrictionScale(PhysicsControl.
Wheels[i].TireFriction);
655 Vehicle4W->WheelSetups = NewWheelSetups;
658 GetWorld()->GetPhysicsScene()->GetPxScene()->lockWrite();
659 Vehicle4W->RecreatePhysicsState();
660 GetWorld()->GetPhysicsScene()->GetPxScene()->unlockWrite();
662 for (int32 i = 0; i < PhysicsWheelsNum; ++i)
664 PxVehicleWheelData PWheelData = Vehicle4W->PVehicle->mWheelsSimData.getWheelData(i);
666 PWheelData.mRadius = PhysicsControl.
Wheels[i].Radius;
667 PWheelData.mMaxSteer = FMath::DegreesToRadians(PhysicsControl.
Wheels[i].MaxSteerAngle);
668 PWheelData.mDampingRate = M2ToCm2(PhysicsControl.
Wheels[i].DampingRate);
669 PWheelData.mMaxBrakeTorque = M2ToCm2(PhysicsControl.
Wheels[i].MaxBrakeTorque);
670 PWheelData.mMaxHandBrakeTorque = M2ToCm2(PhysicsControl.
Wheels[i].MaxHandBrakeTorque);
671 Vehicle4W->PVehicle->mWheelsSimData.setWheelData(i, PWheelData);
673 PxVehicleTireData PTireData = Vehicle4W->PVehicle->mWheelsSimData.getTireData(i);
674 PTireData.mLatStiffX = PhysicsControl.
Wheels[i].LatStiffMaxLoad;
675 PTireData.mLatStiffY = PhysicsControl.
Wheels[i].LatStiffValue;
676 PTireData.mLongitudinalStiffnessPerUnitGravity = PhysicsControl.
Wheels[i].LongStiffValue;
677 Vehicle4W->PVehicle->mWheelsSimData.setTireData(i, PTireData);
682 UWheeledVehicleMovementComponentNW *VehicleNW = Cast<UWheeledVehicleMovementComponentNW>(
683 GetVehicleMovement());
685 check(VehicleNW !=
nullptr);
688 VehicleNW->EngineSetup.TorqueCurve.EditorCurveData = PhysicsControl.
TorqueCurve;
689 VehicleNW->EngineSetup.MaxRPM = PhysicsControl.
MaxRPM;
691 VehicleNW->EngineSetup.MOI = PhysicsControl.
MOI;
694 VehicleNW->EngineSetup.DampingRateZeroThrottleClutchEngaged =
696 VehicleNW->EngineSetup.DampingRateZeroThrottleClutchDisengaged =
700 VehicleNW->TransmissionSetup.bUseGearAutoBox = PhysicsControl.
bUseGearAutoBox;
701 VehicleNW->TransmissionSetup.GearSwitchTime = PhysicsControl.
GearSwitchTime;
702 VehicleNW->TransmissionSetup.ClutchStrength = PhysicsControl.
ClutchStrength;
703 VehicleNW->TransmissionSetup.FinalRatio = PhysicsControl.
FinalRatio;
705 TArray<FVehicleNWGearData> ForwardGears;
711 GearData.
Ratio = Gear.Ratio;
712 GearData.
UpRatio = Gear.UpRatio;
715 ForwardGears.Add(GearData);
718 VehicleNW->TransmissionSetup.ForwardGears = ForwardGears;
721 VehicleNW->Mass = PhysicsControl.
Mass;
725 UPrimitiveComponent *UpdatedPrimitive = Cast<UPrimitiveComponent>(VehicleNW->UpdatedComponent);
726 check(UpdatedPrimitive !=
nullptr);
728 UpdatedPrimitive->BodyInstance.COMNudge = PhysicsControl.
CenterOfMass;
731 VehicleNW->SteeringCurve.EditorCurveData = PhysicsControl.
SteeringCurve;
734 const int PhysicsWheelsNum = PhysicsControl.
Wheels.Num();
739 TArray<FWheelSetup> NewWheelSetups = VehicleNW->WheelSetups;
741 for (int32 i = 0; i < PhysicsWheelsNum; ++i)
743 UVehicleWheel *Wheel = NewWheelSetups[i].WheelClass.GetDefaultObject();
744 check(Wheel !=
nullptr);
747 Wheel->TireConfig = DuplicateObject<UTireConfig>(Wheel->TireConfig,
nullptr);
750 Wheel->TireConfig->SetFrictionScale(PhysicsControl.
Wheels[i].TireFriction);
753 VehicleNW->WheelSetups = NewWheelSetups;
756 GetWorld()->GetPhysicsScene()->GetPxScene()->lockWrite();
757 VehicleNW->RecreatePhysicsState();
758 GetWorld()->GetPhysicsScene()->GetPxScene()->unlockWrite();
760 for (int32 i = 0; i < PhysicsWheelsNum; ++i)
762 PxVehicleWheelData PWheelData = VehicleNW->PVehicle->mWheelsSimData.getWheelData(i);
764 PWheelData.mRadius = PhysicsControl.
Wheels[i].Radius;
765 PWheelData.mMaxSteer = FMath::DegreesToRadians(PhysicsControl.
Wheels[i].MaxSteerAngle);
766 PWheelData.mDampingRate = M2ToCm2(PhysicsControl.
Wheels[i].DampingRate);
767 PWheelData.mMaxBrakeTorque = M2ToCm2(PhysicsControl.
Wheels[i].MaxBrakeTorque);
768 PWheelData.mMaxHandBrakeTorque = M2ToCm2(PhysicsControl.
Wheels[i].MaxHandBrakeTorque);
769 VehicleNW->PVehicle->mWheelsSimData.setWheelData(i, PWheelData);
771 PxVehicleTireData PTireData = VehicleNW->PVehicle->mWheelsSimData.getTireData(i);
772 PTireData.mLatStiffX = PhysicsControl.
Wheels[i].LatStiffMaxLoad;
773 PTireData.mLatStiffY = PhysicsControl.
Wheels[i].LatStiffValue;
774 PTireData.mLongitudinalStiffnessPerUnitGravity = PhysicsControl.
Wheels[i].LongStiffValue;
775 VehicleNW->PVehicle->mWheelsSimData.setTireData(i, PTireData);
783 if (Recorder && Recorder->IsEnabled())
785 Recorder->AddPhysicsControl(*
this);
805 if (GetWorld()->GetFirstPlayerController())
807 ACarlaHUD* hud = Cast<ACarlaHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
815 if (hud->
DebugVehicle == GetVehicleMovementComponent()) {
817 GetVehicleMovementComponent()->StopTelemetry();
823 UE_LOG(LogCarla, Warning, TEXT(
"ACarlaWheeledVehicle::ShowDebugTelemetry:: Cannot find HUD for debug info"));
865 check((uint8)WheelLocation >= 0)
866 UVehicleAnimInstance *VehicleAnim = Cast<UVehicleAnimInstance>(GetMesh()->GetAnimInstance());
867 check(VehicleAnim !=
nullptr)
868 VehicleAnim->SetWheelRotYaw((uint8)WheelLocation, AngleInDeg);
872 UE_LOG(LogTemp, Warning, TEXT(
"Cannot set wheel steer direction. Physics are enabled."))
878 check((uint8)WheelLocation >= 0)
879 UVehicleAnimInstance *VehicleAnim = Cast<UVehicleAnimInstance>(GetMesh()->GetAnimInstance());
880 check(VehicleAnim !=
nullptr)
881 check(VehicleAnim->GetWheeledVehicleMovementComponent() !=
nullptr)
885 return VehicleAnim->GetWheeledVehicleMovementComponent()->Wheels[(uint8)WheelLocation]->GetSteerAngle();
889 return VehicleAnim->GetWheelRotAngle((uint8)WheelLocation);
894 if(!GetCarlaMovementComponent<UDefaultMovementComponent>())
899 UWheeledVehicleMovementComponent* Movement = GetVehicleMovement();
902 check(Movement !=
nullptr);
907 SetActorEnableCollision(
true);
908 auto RootComponent = Cast<UPrimitiveComponent>(GetRootComponent());
909 RootComponent->SetSimulatePhysics(enabled);
910 RootComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
912 UVehicleAnimInstance *VehicleAnim = Cast<UVehicleAnimInstance>(GetMesh()->GetAnimInstance());
913 check(VehicleAnim !=
nullptr)
915 GetWorld()->GetPhysicsScene()->GetPxScene()->lockWrite();
918 Movement->RecreatePhysicsState();
919 VehicleAnim->ResetWheelCustomRotations();
923 Movement->DestroyPhysicsState();
926 GetWorld()->GetPhysicsScene()->GetPxScene()->unlockWrite();
955 Super::EndPlay(EndPlayReason);
961 UE_LOG(LogTemp, Warning, TEXT(
"This door is not configured for this car."));
978 UE_LOG(LogTemp, Warning, TEXT(
"This door is not configured for this car."));
997 DoorComponent->DetachFromComponent(
998 FDetachmentTransformRules(EDetachmentRule::KeepWorld,
false));
999 FTransform DoorInitialTransform =
1001 DoorComponent->SetWorldTransform(DoorInitialTransform);
1002 DoorComponent->SetSimulatePhysics(
true);
1003 DoorComponent->SetCollisionProfileName(TEXT(
"BlockAll"));
1004 float AngleLimit = Constraint->ConstraintInstance.GetAngularSwing1Limit();
1005 FRotator AngularRotationOffset = Constraint->ConstraintInstance.AngularRotationOffset;
1007 if (Constraint->ConstraintInstance.AngularRotationOffset.Yaw < 0.0f)
1009 AngleLimit = -AngleLimit;
1011 Constraint->SetAngularOrientationTarget(FRotator(0, AngleLimit, 0));
1014 Constraint->InitComponentConstraint();
1016 UPhysicsConstraintComponent** CollisionDisable =
1018 if (CollisionDisable)
1020 (*CollisionDisable)->InitComponentConstraint();
1028 FTransform DoorInitialTransform =
1030 DoorComponent->SetSimulatePhysics(
false);
1031 DoorComponent->SetCollisionProfileName(TEXT(
"NoCollision"));
1032 DoorComponent->SetWorldTransform(DoorInitialTransform);
1033 DoorComponent->AttachToComponent(
1034 GetMesh(), FAttachmentTransformRules(EAttachmentRule::KeepWorld,
true));
1044 case 0:
CheckRollover(roll, std::make_pair(130.0, 230.0));
break;
1045 case 1:
CheckRollover(roll, std::make_pair(140.0, 220.0));
break;
1046 case 2:
CheckRollover(roll, std::make_pair(150.0, 210.0));
break;
1047 case 3:
CheckRollover(roll, std::make_pair(160.0, 200.0));
break;
1065 if (threshold_roll.first < roll && roll < threshold_roll.second){
1066 auto RootComponent = Cast<UPrimitiveComponent>(GetRootComponent());
1067 auto angular_velocity = RootComponent->GetPhysicsAngularVelocityInDegrees();
1086 const UObject* World = GetWorld();
1087 TArray<AActor*> ActorsInLevel;
1088 UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), ActorsInLevel);
1101 const UObject* World = GetWorld();
1102 TArray<AActor*> ActorsInLevel;
1103 UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), ActorsInLevel);
1115 UPhysicsConstraintComponent* Component)
1117 return Component->ConstraintInstance.AngularRotationOffset;
1121 UPhysicsConstraintComponent* Component,
const FRotator &NewAngle)
1123 Component->ConstraintInstance.AngularRotationOffset = NewAngle;
void ApplyVehicleControl(const FVehicleControl &Control, EVehicleInputPriority Priority)
void DrawFoliageBoundingBox() const
virtual void ProcessControl(FVehicleControl &Control)
void SetReverse(bool Value)
void SetThrottleInput(float Value)
UBaseCarlaMovementComponent * BaseMovementComponent
void RestoreVehiclePhysicsControl()
bool IsTwoWheeledVehicle()
int RolloverBehaviorTracker
FAckermannController AckermannController
FTransform GetVehicleBoundingBoxTransform() const
Transform of the vehicle's bounding box relative to the vehicle.
carla::rpc::VehicleFailureState GetFailureState() const
float GetVehicleForwardSpeed() const
Forward speed in cm/s. Might be negative if goes backwards.
virtual FVector GetVelocity() const
float RolloverBehaviorForce
float Ratio
Determines the amount of torque multiplication.
FVehiclePhysicsControl GetVehiclePhysicsControl() const
TArray< FName > ConstraintComponentNames
virtual FVector GetVelocity() const override
TArray< UPhysicsConstraintComponent * > ConstraintsComponents
FVehicleLightState LightState
const TArray< int32 > GetFoliageInstancesCloseToVehicle(const UInstancedStaticMeshComponent *Component) const
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason)
void SetSimulatePhysics(bool enabled)
FBoxSphereBounds GetBoxSphereBounds() const
FTimerHandle TimerHandler
void OpenDoor(const EVehicleDoor DoorIdx)
FVector GetVehicleBoundingBoxExtent() const
Extent of the vehicle's bounding box.
float UpRatio
Value of engineRevs/maxEngineRevs that is high enough to gear up.
void UpdateDetectionBox()
void ShowDebugTelemetry(bool Enabled)
float GetMaximumSteerAngle() const
Get the maximum angle at which the front wheel can steer.
TMap< UPhysicsConstraintComponent *, UPrimitiveComponent * > ConstraintDoor
void AddDebugVehicleForTelemetry(UWheeledVehicleMovementComponent *Veh)
static FBoundingBox GetVehicleBoundingBox(const ACarlaWheeledVehicle *Vehicle, uint8 InTagQueried=0xFF)
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
float DampingRateZeroThrottleClutchEngaged
void CloseDoor(const EVehicleDoor DoorIdx)
ACarlaWheeledVehicle(const FObjectInitializer &ObjectInitializer)
void SetWheelSteerDirection(EVehicleWheelLocation WheelLocation, float AngleInDeg)
Set the rotation of the car wheels indicated by the user 0 = FL_VehicleWheel, 1 = FR_VehicleWheel...
bg::model::box< Point3D > Box
static FRotator GetPhysicsConstraintAngle(UPhysicsConstraintComponent *Component)
float GetDetectionSize() const
void UpdateVehiclePhysics(const ACarlaWheeledVehicle *Vehicle)
TArray< float > GetWheelsFrictionScale()
FVector GetVehicleOrientation() const
Orientation vector of the vehicle, pointing forward.
void ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl)
carla::rpc::VehicleFailureState FailureState
bool bAckermannControlActive
void ActivateVelocityControl(const FVector &Velocity)
void SetWheelCollisionNW(UWheeledVehicleMovementComponentNW *VehicleNW, const FVehiclePhysicsControl &PhysicsControl)
carla::SharedPtr< cc::Actor > Actor
void UpdateVehicleState(const ACarlaWheeledVehicle *Vehicle)
void SetFailureState(const carla::rpc::VehicleFailureState &FailureState)
struct ACarlaWheeledVehicle::@1 InputControl
void RemoveReferenceToManager()
void SetSteeringInput(float Value)
virtual void BeginPlay() override
void FlushVehicleControl()
void SetHandbrakeInput(bool Value)
float DampingRateZeroThrottleClutchDisengaged
void DeactivateVelocityControl()
float GetWheelSteerAngle(EVehicleWheelLocation WheelLocation)
void RunLoop(FVehicleControl &Control)
float DampingRateFullThrottle
FVehicleControl LastAppliedControl
virtual int32 GetVehicleCurrentGear() const
void RefreshLightState(const FVehicleLightState &VehicleLightState)
void ApplyRolloverBehavior()
Rollovers tend to have too much angular velocity, resulting in the vehicle doing a full 360ยบ flip...
TMap< UPrimitiveComponent *, UPhysicsConstraintComponent * > CollisionDisableConstraints
void SetWheelCollision(UWheeledVehicleMovementComponent4W *Vehicle4W, const FVehiclePhysicsControl &PhysicsControl)
UBoxComponent * VehicleBounds
void AddVehicle(ACarlaWheeledVehicle *Vehicle)
FTransform LocalToGlobalTransform(const FTransform &InTransform) const
TArray< FGearPhysicsControl > ForwardGears
float DownRatio
Value of engineRevs/maxEngineRevs that is low enough to gear down.
void SetVehicleLightState(const FVehicleLightState &LightState)
TMap< UPrimitiveComponent *, FTransform > DoorComponentsTransform
bool IsInVehicleRange(const FVector &Location) const
void AddReferenceToManager()
int32 GetVehicleCurrentGear() const
Active gear of the vehicle.
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
UVehicleVelocityControl * VelocityControl
void SetBrakeInput(float Value)
void CloseDoorPhys(const EVehicleDoor DoorIdx)
virtual float GetVehicleForwardSpeed() const
void CheckRollover(const float roll, const std::pair< float, float > threshold_roll)
static void SetPhysicsConstraintAngle(UPhysicsConstraintComponent *Component, const FRotator &NewAngle)
FVehiclePhysicsControl LastPhysicsControl
FVector Origin
Origin of the bounding box relative to its owner.
void OpenDoorPhys(const EVehicleDoor DoorIdx)
EVehicleDoor
Type of door to open/close.
FBox GetDetectionBox() const
static void CreateDefaultMovementComponent(ACarlaWheeledVehicle *Vehicle)
void SetWheelsFrictionScale(TArray< float > &WheelsFrictionScale)
FVector Extent
Radii extent of the bounding box.
UWheeledVehicleMovementComponent * DebugVehicle
geom::Transform Transform
bool UseSweepWheelCollision
void SetCarlaMovementComponent(UBaseCarlaMovementComponent *MoementComponent)
void RemoveVehicle(ACarlaWheeledVehicle *Vehicle)
void AdjustVehicleBounds()
FVehicleLightState GetVehicleLightState() const
FTransform GetVehicleTransform() const
Transform of the vehicle.
TArray< FWheelPhysicsControl > Wheels
static ACarlaRecorder * GetRecorder(const UObject *WorldContextObject)