Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ void ATrafficLightManager::SpawnTrafficLights()
SpawnRotation.Roll = 0;
SpawnRotation.Pitch = 0;

AdjustSignHeightToGround(SpawnLocation);

FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.SpawnCollisionHandlingOverride =
Expand Down Expand Up @@ -667,6 +669,8 @@ void ATrafficLightManager::SpawnSignals()
SpawnRotation.Roll = 0;
SpawnRotation.Pitch = 0;

AdjustSignHeightToGround(SpawnLocation);

FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.SpawnCollisionHandlingOverride =
Expand Down Expand Up @@ -724,6 +728,8 @@ void ATrafficLightManager::SpawnSignals()
SpawnRotation.Roll = 0;
SpawnRotation.Pitch = 0;

AdjustSignHeightToGround(SpawnLocation);

FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.SpawnCollisionHandlingOverride =
Expand Down Expand Up @@ -863,3 +869,30 @@ void ATrafficLightManager::RemoveAttachedProps(TArray<AActor*> Actors) const
Actor->Destroy();
}
}

void ATrafficLightManager::AdjustSignHeightToGround(FVector& SpawnLocation) const
{
const FVector Start = SpawnLocation + FVector(0, 0, 10000.0f);
const FVector End = SpawnLocation - FVector(0, 0, 10000.0f);

FHitResult HitResult;
FCollisionQueryParams CollisionParams;
CollisionParams.bTraceComplex = true;
CollisionParams.bReturnPhysicalMaterial = false;

constexpr float ZOffsetSignToGround = 0.5f;
if (GetWorld()->LineTraceSingleByChannel(
HitResult,
Start,
End,
ECC_WorldStatic,
CollisionParams))
{
SpawnLocation.Z = HitResult.Location.Z + ZOffsetSignToGround;
}
else
{
carla::log_warning("Could not find ground for traffic sign placement at location",
TCHAR_TO_UTF8(*SpawnLocation.ToString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class CARLA_API ATrafficLightManager : public AActor

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

void AdjustSignHeightToGround(FVector& SpawnLocation) const;

// Mapped references to ATrafficLightGroup (junction)
UPROPERTY()
TMap<int, ATrafficLightGroup *> TrafficGroups;
Expand Down
Loading