Skip to content

Commit f856729

Browse files
Fixed Traffic Signals being spawned in the air (#9239)
* Add AdjustSignHeightToGround method to ensure traffic signs are placed at the correct height * use variable instead a magic number for the offset, and lowered it to 0.5 cm
1 parent 9bf462d commit f856729

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightManager.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ void ATrafficLightManager::SpawnTrafficLights()
572572
SpawnRotation.Roll = 0;
573573
SpawnRotation.Pitch = 0;
574574

575+
AdjustSignHeightToGround(SpawnLocation);
576+
575577
FActorSpawnParameters SpawnParams;
576578
SpawnParams.Owner = this;
577579
SpawnParams.SpawnCollisionHandlingOverride =
@@ -667,6 +669,8 @@ void ATrafficLightManager::SpawnSignals()
667669
SpawnRotation.Roll = 0;
668670
SpawnRotation.Pitch = 0;
669671

672+
AdjustSignHeightToGround(SpawnLocation);
673+
670674
FActorSpawnParameters SpawnParams;
671675
SpawnParams.Owner = this;
672676
SpawnParams.SpawnCollisionHandlingOverride =
@@ -724,6 +728,8 @@ void ATrafficLightManager::SpawnSignals()
724728
SpawnRotation.Roll = 0;
725729
SpawnRotation.Pitch = 0;
726730

731+
AdjustSignHeightToGround(SpawnLocation);
732+
727733
FActorSpawnParameters SpawnParams;
728734
SpawnParams.Owner = this;
729735
SpawnParams.SpawnCollisionHandlingOverride =
@@ -863,3 +869,30 @@ void ATrafficLightManager::RemoveAttachedProps(TArray<AActor*> Actors) const
863869
Actor->Destroy();
864870
}
865871
}
872+
873+
void ATrafficLightManager::AdjustSignHeightToGround(FVector& SpawnLocation) const
874+
{
875+
const FVector Start = SpawnLocation + FVector(0, 0, 10000.0f);
876+
const FVector End = SpawnLocation - FVector(0, 0, 10000.0f);
877+
878+
FHitResult HitResult;
879+
FCollisionQueryParams CollisionParams;
880+
CollisionParams.bTraceComplex = true;
881+
CollisionParams.bReturnPhysicalMaterial = false;
882+
883+
constexpr float ZOffsetSignToGround = 0.5f;
884+
if (GetWorld()->LineTraceSingleByChannel(
885+
HitResult,
886+
Start,
887+
End,
888+
ECC_WorldStatic,
889+
CollisionParams))
890+
{
891+
SpawnLocation.Z = HitResult.Location.Z + ZOffsetSignToGround;
892+
}
893+
else
894+
{
895+
carla::log_warning("Could not find ground for traffic sign placement at location",
896+
TCHAR_TO_UTF8(*SpawnLocation.ToString()));
897+
}
898+
}

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class CARLA_API ATrafficLightManager : public AActor
6969

7070
void RemoveAttachedProps(TArray<AActor*> Actors) const;
7171

72+
void AdjustSignHeightToGround(FVector& SpawnLocation) const;
73+
7274
// Mapped references to ATrafficLightGroup (junction)
7375
UPROPERTY()
7476
TMap<int, ATrafficLightGroup *> TrafficGroups;

0 commit comments

Comments
 (0)