15#include <util/ue-header-guard-begin.h>
16#include "EngineUtils.h"
17#include "GameFramework/Pawn.h"
18#include "ChaosWheeledVehicleMovementComponent.h"
19#include <util/ue-header-guard-end.h>
25static bool RayCast(
const AActor &Actor,
const FVector &Start,
const FVector &End)
28 static FName TraceTag = FName(TEXT(
"VehicleTrace"));
29 FCollisionQueryParams CollisionParams(TraceTag,
true);
30 CollisionParams.AddIgnoredActor(&Actor);
32 const bool Success = Actor.GetWorld()->LineTraceSingleByObjectType(
36 FCollisionObjectQueryParams(FCollisionObjectQueryParams::AllDynamicObjects),
42 return Success && OutHit.bBlockingHit;
48 const FVector &Direction)
50 const auto ForwardVector =
Vehicle.GetVehicleOrientation();
51 const auto VehicleBounds =
Vehicle.GetVehicleBoundingBoxExtent();
53 FVector NormDirection = Direction.GetSafeNormal();
55 const float Distance = std::max(50.0f, Speed * Speed);
57 const FVector StartCenter =
Vehicle.GetActorLocation() +
58 (ForwardVector * (250.0f + VehicleBounds.X / 2.0f)) + FVector(0.0f, 0.0f, 50.0f);
59 const FVector EndCenter = StartCenter + NormDirection * (Distance + VehicleBounds.X / 2.0f);
61 const FVector StartRight = StartCenter +
62 (FVector(ForwardVector.Y, -ForwardVector.X, ForwardVector.Z) * 100.0f);
63 const FVector EndRight = StartRight + NormDirection * (Distance + VehicleBounds.X / 2.0f);
65 const FVector StartLeft = StartCenter +
66 (FVector(-ForwardVector.Y, ForwardVector.X, ForwardVector.Z) * 100.0f);
67 const FVector EndLeft = StartLeft + NormDirection * (Distance + VehicleBounds.X / 2.0f);
78 std::queue<T> EmptyQueue;
79 Queue.swap(EmptyQueue);
87 : Super(ObjectInitializer)
89 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
93 PrimaryActorTick.bCanEverTick =
true;
94 PrimaryActorTick.TickGroup = TG_PrePhysics;
105 Super::OnPossess(aPawn);
109 UE_LOG(LogCarla, Error, TEXT(
"Controller already possessing a vehicle!"));
112 Vehicle = Cast<ACarlaWheeledVehicle>(aPawn);
116 UE_LOG(LogCarla, Error, TEXT(
"MaximumSteerAngle > 0.0f"));
123 TActorIterator<ACityMapGenerator> It(GetWorld());
124 RoadMap = (It ? It->GetRoadMap() :
nullptr);
130 Super::OnUnPossess();
138 Super::Tick(DeltaTime);
171 ECarlaWheeledVehicleState::FreeDriving :
172 ECarlaWheeledVehicleState::AutopilotOff);
183 const TArray<FVector> &Locations,
184 const bool bOverwriteCurrent)
186 if (bOverwriteCurrent)
190 for (
auto &Location : Locations)
static bool RayCast(const AActor &Actor, const FVector &Start, const FVector &End)
static void ClearQueue(std::queue< T > &Queue)
static bool IsThereAnObstacleAhead(const ACarlaWheeledVehicle &Vehicle, const float Speed, const FVector &Direction)
Base class for CARLA wheeled vehicles.
void SetAIVehicleState(ECarlaWheeledVehicleState InState)
void SetThrottleInput(float Value)
void SetReverse(bool Value)
float GetMaximumSteerAngle() const
Get the maximum angle at which the front wheel can steer.
void SetBrakeInput(float Value)
void SetSteeringInput(float Value)
void FlushVehicleControl()
void ApplyVehicleControl(const FVehicleControl &Control, EVehicleInputPriority Priority)
void SetHandbrakeInput(bool Value)
void ConfigureAutopilot(const bool Enable, const bool KeepState=false)
void OnUnPossess() override
AWheeledVehicleAIController(const FObjectInitializer &ObjectInitializer)
ETrafficLightState TrafficLightState
URandomEngine * RandomEngine
bool IsPossessingAVehicle() const
void OnPossess(APawn *aPawn) override
void SetFixedRoute(const TArray< FVector > &Locations, bool bOverwriteCurrent=true)
Set a fixed route to follow if autopilot is enabled.
void Tick(float DeltaTime) override
~AWheeledVehicleAIController()
std::queue< FVector > TargetLocations
ACarlaWheeledVehicle * Vehicle
void Seed(int32 InSeed)
Seed the random engine.
static int32 GenerateRandomSeed()
Generate a non-deterministic random seed.