Updated the information that traffic lights sent to vehicles

This commit is contained in:
glopezdiest 2022-06-01 15:11:29 +02:00 committed by GitHub
parent e228aa0fff
commit 90c624bc8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 22 deletions

View File

@ -1,5 +1,8 @@
## Latest
* Fixed bug at `Vehicle.get_traffic_light_state()` and `Vehicle.is_at_traffic_light()` causing vehicles to temporarily not lose the information of a traffic light if they moved away from it before it turned green.
* Fixed bug causing the `Vehicle.get_traffic_light_state()` function not notify about the green to yellow and yellow to red light state changes.
* Fixed bug causing the `Vehicle.is_at_traffic_light()` function to return *false* if the traffic light was green.
* Fixed bug causing the scene lights to return an incorrect location at large maps.
* Fixed bug causing the `world.ground_projection()` function to return an incorrect location at large maps.
* Added failure state to vehicles, which can be retrieved by using `Vehicle.get_failure_state()`. Only Rollover failure state is currently supported.

View File

@ -78,11 +78,8 @@ void ATrafficLightBase::NotifyWheeledVehicle(ACarlaWheeledVehicle *Vehicle)
if (Controller != nullptr)
{
Controller->SetTrafficLightState(GetTrafficLightState());
if (GetTrafficLightState() != ETrafficLightState::Green)
{
Vehicles.Add(Controller);
Controller->SetTrafficLight(this);
}
Vehicles.Add(Controller);
Controller->SetTrafficLight(this);
}
}
}

View File

@ -93,7 +93,8 @@ void UTrafficLightComponent::GenerateTrafficLightBox(const FTransform BoxTransfo
const FVector BoxSize)
{
UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &UTrafficLightComponent::OnOverlapTriggerBox);
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &UTrafficLightComponent::OnBeginOverlapTriggerBox);
BoxComponent->OnComponentEndOverlap.AddDynamic(this, &UTrafficLightComponent::OnEndOverlapTriggerBox);
AddEffectTriggerVolume(BoxComponent);
}
@ -116,16 +117,8 @@ void UTrafficLightComponent::SetLightState(ETrafficLightState NewState)
if (Controller != nullptr)
{
Controller->SetTrafficLightState(LightState);
if (LightState == ETrafficLightState::Green)
{
Controller->SetTrafficLight(nullptr);
}
}
}
if (LightState == ETrafficLightState::Green)
{
Vehicles.Empty();
}
}
ETrafficLightState UTrafficLightComponent::GetLightState() const
@ -161,7 +154,7 @@ const UTrafficLightController* UTrafficLightComponent::GetController() const
return TrafficLightController;
}
void UTrafficLightComponent::OnOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
void UTrafficLightComponent::OnBeginOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
AActor *OtherActor,
UPrimitiveComponent *OtherComp,
int32 OtherBodyIndex,
@ -176,12 +169,27 @@ void UTrafficLightComponent::OnOverlapTriggerBox(UPrimitiveComponent *Overlapped
if (VehicleController)
{
VehicleController->SetTrafficLightState(LightState);
if (LightState != ETrafficLightState::Green)
{
Vehicles.Add(VehicleController);
VehicleController->SetTrafficLight(
Cast<ATrafficLightBase>(GetOwner()));
}
Vehicles.Add(VehicleController);
VehicleController->SetTrafficLight(Cast<ATrafficLightBase>(GetOwner()));
}
}
}
void UTrafficLightComponent::OnEndOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
AActor *OtherActor,
UPrimitiveComponent *OtherComp,
int32 OtherBodyIndex)
{
ACarlaWheeledVehicle * Vehicle = Cast<ACarlaWheeledVehicle>(OtherActor);
if (Vehicle)
{
AWheeledVehicleAIController* VehicleController =
Cast<AWheeledVehicleAIController>(Vehicle->GetController());
if (VehicleController)
{
VehicleController->SetTrafficLightState(ETrafficLightState::Green);
VehicleController->SetTrafficLight(nullptr);
Vehicles.Remove(VehicleController);
}
}
}

View File

@ -55,13 +55,21 @@ public:
protected:
UFUNCTION(BlueprintCallable)
void OnOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
void OnBeginOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
AActor *OtherActor,
UPrimitiveComponent *OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult);
UFUNCTION(BlueprintCallable)
void OnEndOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
AActor *OtherActor,
UPrimitiveComponent *OtherComp,
int32 OtherBodyIndex);
private:
friend ATrafficLightManager;