106 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
107 UChaosWheeledVehicleMovementComponent* GetChaosWheeledVehicleMovementComponent()
const
109 return Cast<UChaosWheeledVehicleMovementComponent>(GetVehicleMovement());
113 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
116 return LastAppliedControl;
120 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
123 return LastAppliedAckermannControl;
128 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
129 FTransform GetVehicleTransform()
const
131 return GetActorTransform();
135 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
136 float GetVehicleForwardSpeed()
const;
139 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
140 FVector GetVehicleOrientation()
const;
143 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
144 int32 GetVehicleCurrentGear()
const;
147 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
148 FTransform GetVehicleBoundingBoxTransform()
const;
151 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
152 FVector GetVehicleBoundingBoxExtent()
const;
155 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
156 UBoxComponent *GetVehicleBoundingBox()
const
158 return VehicleBounds;
162 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
163 float GetMaximumSteerAngle()
const;
178 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
184 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
191 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
194 FVector GetCenterOfMass(UChaosWheeledVehicleMovementComponent &VehicleMovComponent)
const;
196 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
198 return AckermannController.GetSettings();
201 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
202 void RestoreVehiclePhysicsControl();
204 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
212 return AckermannController.ApplySettings(AckermannControllerSettings);
215 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
216 void SetSimulatePhysics(
bool enabled);
222 UFUNCTION(BlueprintNativeEvent)
223 bool IsTwoWheeledVehicle();
224 virtual
bool IsTwoWheeledVehicle_Implementation() {
252 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
253 FName RiderMeshComponentName = TEXT("SkeletalMesh");
255 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CARLA Wheeled
Vehicle|Rider")
256 FName VehicleMeshSeatSocketName = TEXT("Seat");
271 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CARLA Wheeled
Vehicle|Rider")
272 float RiderSeatSmoothingSpeed = 10.0f;
295 UFUNCTION(BlueprintPure, Category = "CARLA Wheeled
Vehicle|Rider")
296 FTransform GetCachedVehicleSocketWorldTransform(FName SocketName)
const
322 FTransform PredictedMeshTransform = SmoothedVehicleMeshTransform;
323 if (
const UWorld* World = GetWorld())
325 const float TimeSinceCache = World->GetTimeSeconds() - CachedVehicleTransformsTimeSeconds;
335 FVector AngularVelocityRadians = FMath::DegreesToRadians(CachedVehicleWorldAngularVelocityDegrees);
336 AngularVelocityRadians.X = 0.0f;
337 AngularVelocityRadians.Y = 0.0f;
338 const FQuat DeltaRotation = FQuat::MakeFromRotationVector(AngularVelocityRadians * TimeSinceCache);
339 PredictedMeshTransform.SetRotation((DeltaRotation * PredictedMeshTransform.GetRotation()).GetNormalized());
348 FVector VelocityForExtrapolation = CachedVehicleWorldVelocity;
349 VelocityForExtrapolation.Z = 0.0f;
350 PredictedMeshTransform.AddToTranslation(VelocityForExtrapolation * TimeSinceCache);
369 static const FName LeftPedalSocket(TEXT(
"LeftPedalSocket"));
370 static const FName RightPedalSocket(TEXT(
"RightPedalSocket"));
371 static const FName LeftPedalPivotBone(TEXT(
"LeftPedalGeo"));
372 static const FName RightPedalPivotBone(TEXT(
"RightPedalGeo"));
373 if (SocketName == LeftPedalSocket || SocketName == RightPedalSocket)
375 const FName PivotBoneName = (SocketName == LeftPedalSocket) ? LeftPedalPivotBone : RightPedalPivotBone;
376 const FTransform* CachedSocket = CachedVehicleSocketTransforms.Find(SocketName);
377 const FTransform* CachedPivot = CachedVehicleSocketTransforms.Find(PivotBoneName);
378 if (CachedSocket && CachedPivot)
380 const FTransform SocketRelativeToPivot = CachedSocket->GetRelativeTransform(*CachedPivot);
381 FTransform PredictedPivot = CachedPivot->GetRelativeTransform(CachedVehicleMeshTransform) * PredictedMeshTransform;
384 const float SignedPedalAngle = (SocketName == LeftPedalSocket) ? -PedalRotationAngle : PedalRotationAngle;
385 const FQuat ComponentSpaceRotation(FRotator(SignedPedalAngle, 0.0f, 0.0f));
386 PredictedPivot.SetRotation((ComponentSpaceRotation * PredictedMeshTransform.GetRotation()).GetNormalized());
387 return SocketRelativeToPivot * PredictedPivot;
391 if (
const FTransform* CachedSocket = CachedVehicleSocketTransforms.Find(SocketName))
393 return CachedSocket->GetRelativeTransform(CachedVehicleMeshTransform) * PredictedMeshTransform;
395 return FTransform::Identity;
403 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
404 FRotator RiderSeatRelativeRotationOffset = FRotator(0.0f, -90.0f, 15.0f);
423 UFUNCTION(BlueprintPure, Category = "CARLA Wheeled
Vehicle|Rider")
424 float GetPedalRotation()
const
426 return PedalRotationAngle;
432 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"CARLA Wheeled Vehicle|Rider")
433 float PedalRotationDegreesPerCm = 0.5f;
435 void PrintROS2Message(const
char* Message);
444 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
447 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
450 bool IsAckermannControlActive()
const
452 return bAckermannControlActive;
455 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
456 void ActivateVelocityControl(
const FVector &Velocity);
458 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
459 void DeactivateVelocityControl();
461 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
462 void ActivateAccelerationControl(
const FVector &Acceleration);
464 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
465 void DeactivateAccelerationControl();
468 void ApplyVehicleAccelerationControl(
float LongitudinalAccelerationMps2,
float Steer,
float SteerSpeed);
470 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
471 void ShowDebugTelemetry(
bool Enabled);
474 void FlushVehicleControl();
483 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
484 void SetThrottleInput(
float Value);
486 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
487 void SetSteeringInput(
float Value);
489 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
490 void SetBrakeInput(
float Value);
492 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
493 void SetReverse(
bool Value);
495 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
498 SetReverse(!LastAppliedControl.bReverse);
501 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
502 void SetHandbrakeInput(
bool Value);
504 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
507 SetHandbrakeInput(
true);
510 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
511 void ReleaseHandbrake()
513 SetHandbrakeInput(
false);
516 TArray<float> GetWheelsFrictionScale();
518 void SetWheelsFrictionScale(TArray<float> &WheelsFrictionScale);
522 template<
typename T = UBaseCarlaMovementComponent>
525 return Cast<T>(BaseMovementComponent);
536 virtual void BeginPlay()
override;
537 virtual void TickActor(
float DeltaTime,
enum ELevelTick TickType, FActorTickFunction& ThisTickFunction)
override;
538 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason);
540 UFUNCTION(BlueprintImplementableEvent)
543 UFUNCTION(BlueprintCallable, CallInEditor)
544 void AdjustVehicleBounds();
546 UPROPERTY(Category="Door Animation", EditAnywhere, BlueprintReadWrite)
547 TArray<FName> ConstraintComponentNames;
549 UPROPERTY(Category="Door Animation", EditAnywhere, BlueprintReadWrite)
550 float DoorOpenStrength = 100.0f;
552 UFUNCTION(BlueprintCallable, CallInEditor)
553 void ResetConstraints();
567 UPROPERTY(Category =
"AI Controller", VisibleAnywhere)
570 UPROPERTY(Category = "CARLA Wheeled
Vehicle", EditAnywhere)
571 TObjectPtr<UVehicleVelocityControl> VelocityControl;
573 UPROPERTY(Category = "CARLA Wheeled
Vehicle", EditAnywhere)
574 TObjectPtr<UVehicleAccelerationControl> AccelerationControl;
583 void ApplyWheelPhysicsControl();
585 bool bAckermannControlActive = false;
588 float RolloverBehaviorForce = 0.35;
589 int RolloverBehaviorTracker = 0;
590 float RolloverFlagTime = 5.0f;
592 carla::rpc::VehicleFailureState FailureState =
carla::rpc::VehicleFailureState::None;
598 bool bHasSavedVehicleLightDefault = false;
599 float SavedVehicleLightIntensity = 1.0f;
600 TMap<FString,
float> SavedVehicleLightGroupIntensity;
601 void ApplyVehicleLightDefaultsForCurrentState();
609 TObjectPtr<USkeletalMeshComponent> RiderMeshComponent =
nullptr;
612 TObjectPtr<USkeletalMeshComponent> VehicleMeshForRiderSeat =
nullptr;
614 bool bRiderComponentsResolved = false;
616 void ResolveRiderComponentsIfNeeded();
622 void OnRiderBoneTransformsFinalized();
630 TMap<FName, FTransform> CachedVehicleSocketTransforms;
631 FTransform CachedVehicleMeshTransform;
632 FVector CachedVehicleWorldVelocity = FVector::ZeroVector;
633 FVector CachedVehicleWorldAngularVelocityDegrees = FVector::ZeroVector;
634 float CachedVehicleTransformsTimeSeconds = 0.0f;
639 FTransform SmoothedVehicleMeshTransform;
640 bool bSmoothedVehicleMeshTransformInitialized = false;
645 float PedalRotationAngle = 0.0f;
648 UPROPERTY(Category = "CARLA Wheeled
Vehicle", EditDefaultsOnly)
649 float DetectionSize { 750.0f };
651 UPROPERTY(Category =
"CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly)
652 FBox FoliageBoundingBox;
654 UPROPERTY(Category = "CARLA Wheeled
Vehicle", EditAnywhere)
655 TObjectPtr<UBoxComponent> VehicleBounds;
658 FBox GetDetectionBox() const;
661 float GetDetectionSize() const;
664 void UpdateDetectionBox();
667 const TArray<int32> GetFoliageInstancesCloseToVehicle(const UInstancedStaticMeshComponent* Component) const;
669 UFUNCTION(BlueprintCallable)
670 void DrawFoliageBoundingBox() const;
673 FBoxSphereBounds GetBoxSphereBounds() const;
676 bool IsInVehicleRange(const FVector& Location) const;
681 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
684 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
688 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
691 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
696 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
699 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
704 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
705 void SetWheelAnimationOverride(
bool bEnabled);
707 bool IsWheelAnimationOverridden()
const {
return bWheelAnimationOverridden; }
714 bool IsSimulatedByChaos()
const;
716 bool HasWheel(int32 WheelIndex)
const;
720 bool HasCarlaVehicleAnimation()
const;
724 float GetWheelRadius(int32 WheelIndex)
const;
727 FVector GetWheelSuspensionAxis(int32 WheelIndex)
const;
730 FWheelAnimationData GetDrawnWheelPose(int32 WheelIndex)
const;
732 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
735 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
738 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
741 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
744 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
745 void RecordDoorChange(
const EVehicleDoor DoorIdx,
const bool bIsOpen);
749 TArray<TPair<int32, FTransform>> GetOpenDoorPoses()
const;
754 void SetMirroredDoorPoses(
const TArray<TPair<int32, FTransform>> &OpenDoors);
756 virtual FVector GetVelocity()
const override;
761 void SetMirroredMotion(
const FVector &Velocity,
float ForwardSpeed);
763 void ClearMirroredMotion();
767 return bHasMirroredMotion;
775 bHasMirroredGear =
true;
777 bMirroredManualGearShift = bManualGearShift;
778 bMirroredSimulatingPhysics = bSimulatingPhysics;
783 return bMirroredManualGearShift;
788 return bMirroredSimulatingPhysics;
792 FPoseSnapshot GetWorldTransformedPose();
795 UPROPERTY(Category="CARLA Wheeled
Vehicle", EditAnywhere)
796 float CarSimOriginOffset = 150.f;
799 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere)
800 bool bIsNWVehicle = false;
802 void SetRolloverFlag();
804 carla::rpc::VehicleFailureState GetFailureState() const;
806 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
807 static FRotator GetPhysicsConstraintAngle(UPhysicsConstraintComponent* Component);
808 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
809 static
void SetPhysicsConstraintAngle(
810 UPhysicsConstraintComponent*Component, const FRotator &NewAngle);
814 bool bHasMirroredMotion = false;
816 FVector MirroredVelocity = FVector::ZeroVector;
818 float MirroredForwardSpeed = 0.0f;
820 bool bHasMirroredGear = false;
822 int32 MirroredGear = 0;
824 bool bMirroredManualGearShift = false;
826 bool bMirroredSimulatingPhysics = false;
828 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere)
829 bool bPhysicsEnabled = true;
832 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
835 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
836 TArray<UPhysicsConstraintComponent*> ConstraintsComponents;
838 bool bWheelAnimationOverridden = false;
840 TArray<FWheelAnimationData> OverriddenWheelPoses;
844 FWheelAnimationData *GetOverriddenWheelPoseOrWarn(
EVehicleWheelLocation WheelLocation, const TCHAR *Caller);
846 bool HasWheelOrWarn(int32 WheelIndex, const TCHAR *Caller) const;
849 const UChaosVehicleWheel *GetSimulatedWheel(int32 WheelIndex) const;
853 FWheelAnimationData GetWheelPose(int32 WheelIndex) const;
856 TArray<FWheelAnimationData> GetWheelPoses() const;
860 void SeedChaosWheels(const TArray<FWheelAnimationData> &Poses);
864 void ArmSeedRewrite(TArray<
float> Spins);
866 void DisarmSeedRewrite();
868 void OnSeedPreTick(FPhysScene_Chaos *Scene,
float DeltaSeconds);
870 void OnSeedPostTick(FChaosScene *Scene);
873 TArray<
float> PendingSeedSpins;
875 bool bSeedStepStarted = false;
877 FDelegateHandle SeedPreTickHandle;
879 FDelegateHandle SeedPostTickHandle;
881 const UChaosVehicleWheel *GetWheelDefaults(int32 WheelIndex) const;
883 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
884 TMap<UPhysicsConstraintComponent*, UPrimitiveComponent*> ConstraintDoor;
887 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
888 TMap<UPrimitiveComponent*, FTransform> DoorComponentsTransform;
890 UPROPERTY(Category="CARLA Wheeled
Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
891 TMap<UPrimitiveComponent*, UPhysicsConstraintComponent*> CollisionDisableConstraints;
895 UFUNCTION(Category = "CARLA Wheeled
Vehicle", BlueprintCallable)
896 void ApplyRolloverBehavior();
898 void CheckRollover(const
float roll, const
std::pair<
float,
float> threshold_roll);
900 void AddReferenceToManager();
901 void RemoveReferenceToManager();
909 void ActivateVehicleLightComponents();
912 FTimerHandle TimerHandler;
914 float SpeedAnim { 0.0f };
915 float RotationAnim { 0.0f };
918 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
919 float GetSpeedAnim()
const {
return SpeedAnim; }
921 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
922 void SetSpeedAnim(
float Speed) { SpeedAnim = Speed; }
924 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
925 float GetRotationAnim()
const {
return RotationAnim; }
927 UFUNCTION(Category =
"CARLA Wheeled Vehicle", BlueprintCallable)
928 void SetRotationAnim(
float Rotation) { RotationAnim = Rotation; }