CARLA
Loading...
Searching...
No Matches
ActorAttacher.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8#include "Carla.h"
9#include "GameFramework/SpringArmComponent.h"
10
12 AActor *Child,
13 AActor *Parent)
14{
15 auto SpringArm = NewObject<USpringArmComponent>(Parent);
16
17 // Child location negated to compensate for the spring arm rotation (rotated
18 // from the "other end" of the arm).
19 const auto ChildLocation = -Child->GetActorLocation();
20 Child->SetActorLocation(FVector::ZeroVector);
21
22 // Adding Z-offset to avoid colliding against the ground on bumpy terrain.
23 SpringArm->TargetOffset = FVector(0.0f, 0.0f, 30.0f);
24 SpringArm->bDoCollisionTest = true;
25
26 FRotator LookAt = FRotationMatrix::MakeFromX(ChildLocation).Rotator();
27 SpringArm->SetRelativeRotation(LookAt);
28 SpringArm->SetupAttachment(Parent->GetRootComponent());
29
30 SpringArm->TargetArmLength = ChildLocation.Size();
31 SpringArm->bEnableCameraRotationLag = true;
32 SpringArm->CameraRotationLagSpeed = 8.0f;
33
34 SpringArm->bInheritPitch = false;
35 SpringArm->bInheritRoll = false;
36 SpringArm->bInheritYaw = true;
37
38 SpringArm->AttachToComponent(
39 Parent->GetRootComponent(),
40 FAttachmentTransformRules::KeepRelativeTransform);
41 SpringArm->RegisterComponent();
42
43 auto ChildComp = NewObject<UChildActorComponent>(Parent);
44 ChildComp->SetupAttachment(
46 USpringArmComponent::SocketName);
47 Child->AttachToComponent(
48 ChildComp,
49 FAttachmentTransformRules::KeepRelativeTransform);
50 ChildComp->RegisterComponent();
51}
52
54 AActor *Child,
55 AActor *Parent)
56{
57 auto SpringArm = NewObject<USpringArmComponent>(Parent);
58
59 // Child location negated to compensate for the spring arm rotation (rotated
60 // from the "other end" of the arm).
61 const auto ChildLocation = -Child->GetActorLocation();
62 Child->SetActorLocation(FVector::ZeroVector);
63
64 // Adding Z-offset to avoid colliding against the ground on bumpy terrain.
65 SpringArm->TargetOffset = FVector(0.0f, 0.0f, 0.0f);
66 SpringArm->bDoCollisionTest = false;
67
68 FRotator LookAt = FRotationMatrix::MakeFromX(ChildLocation).Rotator();
69 SpringArm->SetRelativeRotation(LookAt);
70 SpringArm->SetupAttachment(Parent->GetRootComponent());
71
72 SpringArm->TargetArmLength = ChildLocation.Size();
73 SpringArm->bEnableCameraRotationLag = true;
74 SpringArm->CameraRotationLagSpeed = 8.0f;
75
76 SpringArm->bInheritPitch = false;
77 SpringArm->bInheritRoll = false;
78 SpringArm->bInheritYaw = true;
79
80 SpringArm->AttachToComponent(
81 Parent->GetRootComponent(),
82 FAttachmentTransformRules::KeepRelativeTransform);
83 SpringArm->RegisterComponent();
84
85 auto ChildComp = NewObject<UChildActorComponent>(Parent);
86 ChildComp->SetupAttachment(
88 USpringArmComponent::SocketName);
89 Child->AttachToComponent(
90 ChildComp,
91 FAttachmentTransformRules::KeepRelativeTransform);
92 ChildComp->RegisterComponent();
93}
94
96 AActor *Child,
97 AActor *Parent,
98 const EAttachmentType AttachmentType)
99{
100 check(Child != nullptr);
101 check(Parent != nullptr);
102
103 switch (AttachmentType)
104 {
106 Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform);
107 break;
110 break;
113 break;
114 default:
115 UE_LOG(LogCarla, Fatal, TEXT("Invalid attachment type"));
116 }
117
118 Child->SetOwner(Parent);
119}
static void UActorAttacher_AttachActorsWithSpringArmGhost(AActor *Child, AActor *Parent)
static void UActorAttacher_AttachActorsWithSpringArm(AActor *Child, AActor *Parent)
EAttachmentType
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType)