Removed collision from signals defined in the middle of a driving lane.

This commit is contained in:
Axel1092 2020-03-30 12:39:49 +02:00 committed by Axel1092
parent d9c4de2c54
commit e7082fae9f
1 changed files with 46 additions and 0 deletions

View File

@ -259,6 +259,29 @@ void ATrafficLightManager::SpawnTrafficLights()
TrafficLight->GetRootComponent(),
FAttachmentTransformRules::KeepRelativeTransform);
auto ClosestWaypointToSignal =
GetMap()->GetClosestWaypointOnRoad(CarlaTransform.location);
if (ClosestWaypointToSignal)
{
auto SignalDistanceToRoad =
(GetMap()->ComputeTransform(ClosestWaypointToSignal.get()).location - CarlaTransform.location).Length();
double LaneWidth = GetMap()->GetLaneWidth(ClosestWaypointToSignal.get());
if(SignalDistanceToRoad < LaneWidth / 2.0)
{
UE_LOG(LogCarla, Warning,
TEXT("Traffic light %s overlaps a driving lane. Disabling collision..."),
*TrafficLightComponent->GetSignId());
TArray<UPrimitiveComponent*> Primitives;
TrafficLight->GetComponents(Primitives);
for (auto* Primitive : Primitives)
{
Primitive->SetCollisionProfileName(TEXT("NoCollision"));
}
}
}
RegisterLightComponent(TrafficLightComponent);
}
}
@ -299,6 +322,29 @@ void ATrafficLightManager::SpawnSignals()
FAttachmentTransformRules::KeepRelativeTransform);
SignComponent->InitializeSign(GetMap().get());
auto ClosestWaypointToSignal =
GetMap()->GetClosestWaypointOnRoad(CarlaTransform.location);
if (ClosestWaypointToSignal)
{
auto SignalDistanceToRoad =
(GetMap()->ComputeTransform(ClosestWaypointToSignal.get()).location - CarlaTransform.location).Length();
double LaneWidth = GetMap()->GetLaneWidth(ClosestWaypointToSignal.get());
if(SignalDistanceToRoad < LaneWidth / 2.0)
{
UE_LOG(LogCarla, Warning,
TEXT("Traffic light %s overlaps a driving lane. Disabling collision..."),
*SignComponent->GetSignId());
TArray<UPrimitiveComponent*> Primitives;
TrafficSign->GetComponents(Primitives);
for (auto* Primitive : Primitives)
{
Primitive->SetCollisionProfileName(TEXT("NoCollision"));
}
}
}
TrafficSignComponents.Add(SignComponent->GetSignId(), SignComponent);
TrafficSigns.Add(TrafficSign);