16 #include "EngineUtils.h" 17 #include "GameFramework/Pawn.h" 18 #include "WheeledVehicleMovementComponent.h" 27 static FName TraceTag = FName(TEXT(
"VehicleTrace"));
28 FCollisionQueryParams CollisionParams(TraceTag,
true);
29 CollisionParams.AddIgnoredActor(&Actor);
31 const bool Success = Actor.GetWorld()->LineTraceSingleByObjectType(
35 FCollisionObjectQueryParams(FCollisionObjectQueryParams::AllDynamicObjects),
41 return Success && OutHit.bBlockingHit;
47 const FVector &Direction)
52 FVector NormDirection = Direction.GetSafeNormal();
54 const float Distance = std::max(50.0f, Speed * Speed);
56 const FVector StartCenter = Vehicle.GetActorLocation() +
57 (ForwardVector * (250.0f + VehicleBounds.X / 2.0f)) + FVector(0.0f, 0.0f, 50.0f);
58 const FVector EndCenter = StartCenter + NormDirection * (Distance + VehicleBounds.X / 2.0f);
60 const FVector StartRight = StartCenter +
61 (FVector(ForwardVector.Y, -ForwardVector.X, ForwardVector.Z) * 100.0f);
62 const FVector EndRight = StartRight + NormDirection * (Distance + VehicleBounds.X / 2.0f);
64 const FVector StartLeft = StartCenter +
65 (FVector(-ForwardVector.Y, ForwardVector.X, ForwardVector.Z) * 100.0f);
66 const FVector EndLeft = StartLeft + NormDirection * (Distance + VehicleBounds.X / 2.0f);
69 RayCast(Vehicle, StartCenter, EndCenter) ||
70 RayCast(Vehicle, StartRight, EndRight) ||
71 RayCast(Vehicle, StartLeft, EndLeft);
77 std::queue<T> EmptyQueue;
78 Queue.swap(EmptyQueue);
86 : Super(ObjectInitializer)
88 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
92 PrimaryActorTick.bCanEverTick =
true;
93 PrimaryActorTick.TickGroup = TG_PrePhysics;
104 Super::OnPossess(aPawn);
108 UE_LOG(LogCarla, Error, TEXT(
"Controller already possessing a vehicle!"));
111 Vehicle = Cast<ACarlaWheeledVehicle>(aPawn);
119 TActorIterator<ACityMapGenerator> It(GetWorld());
120 RoadMap = (It ? It->GetRoadMap() :
nullptr);
126 Super::OnUnPossess();
134 Super::Tick(DeltaTime);
167 ECarlaWheeledVehicleState::FreeDriving :
168 ECarlaWheeledVehicleState::AutopilotOff);
179 const TArray<FVector> &Locations,
180 const bool bOverwriteCurrent)
182 if (bOverwriteCurrent)
void ApplyVehicleControl(const FVehicleControl &Control, EVehicleInputPriority Priority)
void SetReverse(bool Value)
void SetFixedRoute(const TArray< FVector > &Locations, bool bOverwriteCurrent=true)
Set a fixed route to follow if autopilot is enabled.
void SetThrottleInput(float Value)
void SetAIVehicleState(ECarlaWheeledVehicleState InState)
URandomEngine * RandomEngine
void Tick(float DeltaTime) override
std::queue< FVector > TargetLocations
FVector GetVehicleBoundingBoxExtent() const
Extent of the vehicle's bounding box.
void OnPossess(APawn *aPawn) override
float GetMaximumSteerAngle() const
Get the maximum angle at which the front wheel can steer.
void OnUnPossess() override
static void ClearQueue(std::queue< T > &Queue)
static bool RayCast(const AActor &Actor, const FVector &Start, const FVector &End)
FVector GetVehicleOrientation() const
Orientation vector of the vehicle, pointing forward.
ETrafficLightState TrafficLightState
carla::SharedPtr< cc::Actor > Actor
ACarlaWheeledVehicle * Vehicle
void ConfigureAutopilot(const bool Enable, const bool KeepState=false)
void SetSteeringInput(float Value)
void Seed(int32 InSeed)
Seed the random engine.
bool IsPossessingAVehicle() const
void FlushVehicleControl()
void SetHandbrakeInput(bool Value)
~AWheeledVehicleAIController()
AWheeledVehicleAIController(const FObjectInitializer &ObjectInitializer)
static bool IsThereAnObstacleAhead(const ACarlaWheeledVehicle &Vehicle, const float Speed, const FVector &Direction)
void SetBrakeInput(float Value)
Base class for CARLA wheeled vehicles.
static int32 GenerateRandomSeed()
Generate a non-deterministic random seed.