CARLA
Loading...
Searching...
No Matches
WalkerBase.h
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
7#pragma once
8
9#include <util/ue-header-guard-begin.h>
10#include "GameFramework/Character.h"
11#include <util/ue-header-guard-end.h>
12
13#include "WalkerBase.generated.h"
14
16
17UCLASS()
18class CARLA_API AWalkerBase : public ACharacter
19{
20
21 GENERATED_BODY()
22
23public:
24
25 AWalkerBase(const FObjectInitializer &ObjectInitializer);
26
27 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
28 bool bAlive = true;
29
30 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
31 float LifeSpanAfterDeath = 10.0f;
32
33 /// Whether this walker was spawned riding a wheelchair (the
34 /// "use_wheelchair" user attribute). The walker blueprint reads it to
35 /// attach the wheelchair mesh; the bounding-box calculator enlarges the
36 /// walker bounds accordingly.
37 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
38 bool bUsesWheelChair = false;
39
40 /// A vehicle touching the walker while moving at least this fast
41 /// (cm/s) kills it - ue4-dev parity, where any moving-vehicle contact
42 /// was lethal. The threshold only exempts effectively stationary
43 /// vehicles (a walker bumping into a parked or stopped car survives).
44 /// It must stay low: an alive walker's capsule is query-only, so a
45 /// sub-threshold *moving* contact has no physical response at all and
46 /// the car visibly interpenetrates the standing pedestrian.
47 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
48 float VehicleKillSpeed = 50.0f;
49
50 /// How far beyond the capsule radius the vehicle proximity check
51 /// reaches (cm). The margin makes the kill trigger before the first
52 /// physical contact: the capsule is a kinematic body, so to a
53 /// simulating vehicle it is an infinite-mass wall - the impulse of a
54 /// real contact is what used to launch and spin cars. The
55 /// capsule is query-only, so vehicles never physically contact it -
56 /// what launched cars was the wheel suspension raycasts riding the
57 /// blocking capsule like a rigid bollard. The kill therefore fires
58 /// from this proximity poll just before the wheels reach the capsule,
59 /// and the collision event is delivered to the vehicle's sensors
60 /// explicitly from Kill().
61 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
62 float VehicleSensorMargin = 50.0f;
63
64 /// Vehicle proximity poll period in seconds. A timer rather than
65 /// Tick(): the walker blueprints keep actor tick disabled for
66 /// performance, and the timer must not depend on that.
67 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
68 float VehicleSensorPeriod = 0.02f;
69
70 /// Lateral clearance (cm) added on top of the capsule radius and
71 /// sensor margin when testing a fast vehicle's predicted path. Stands
72 /// in for the vehicle body's half width, since the prediction sweeps
73 /// the actor center, not the collision geometry.
74 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
75 float VehicleBodyAllowance = 90.0f;
76
77 /// Fastest closing speed (cm/s) the proximity query is sized for
78 /// (default 300 km/h). Only affects the overlap query radius; the
79 /// per-vehicle path prediction uses the vehicle's actual velocity.
80 UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
81 float VehicleSensorSpeedBound = 8333.0f;
82
83 UFUNCTION(BlueprintCallable)
85 {
86 SetLifeSpan(LifeSpanAfterDeath);
87 }
88
89 /// Kill the walker as if run over: stop navigation and movement, stop
90 /// blocking vehicles, ragdoll (or play the directional death animation
91 /// when the episode requests deterministic ragdolls) and start the
92 /// after-death life span. Idempotent.
93 UFUNCTION(BlueprintCallable)
94 void Kill(FVector ImpactVelocity, AActor *Killer = nullptr);
95
96 /// Re-tag this walker's components. Called by the walker blueprint after
97 /// attaching a wheelchair mesh, as freshly attached components carry no
98 /// semantic-segmentation tag.
99 UFUNCTION(BlueprintCallable)
100 void TagWheelchair();
101
102 /// Attach the wheelchair prop to the walker and switch the walker to the
103 /// sitting animation. Called by the walker factory right after spawn when
104 /// the "use_wheelchair" attribute is set (ue4-dev did this from the
105 /// factory blueprint's AddWheelchairToWalker). All content is soft-loaded:
106 /// if the wheelchair assets are missing the walker stays a normal
107 /// pedestrian and a warning is logged. Idempotent.
108 UFUNCTION(BlueprintCallable)
109 void AttachWheelchair();
110
111 /// The wheelchair mesh attached by AttachWheelchair(), null for walkers
112 /// spawned without one.
113 UPROPERTY(Category="Walker Base", BlueprintReadOnly, VisibleAnywhere)
114 TObjectPtr<USkeletalMeshComponent> WheelchairComponent = nullptr;
115
116 virtual void BeginPlay() override;
117
118 /// Teleport-driven walkers (client-side crowd, replayer) skip overlap queries; the body mesh stays visible to sensors.
119 void SetTeleportDriven(bool bEnable);
120
121private:
122
123 /// Collision state SetTeleportDriven() suspended, restored when the walker moves by itself again.
125 {
126 TWeakObjectPtr<UPrimitiveComponent> Primitive;
127 ECollisionEnabled::Type CollisionEnabled;
129 };
130 TArray<FSuspendedPrimitive> SuspendedPrimitives;
131
132 UFUNCTION()
133 void OnBodyHit(AActor *SelfActor, AActor *OtherActor,
134 FVector NormalImpulse, const FHitResult &Hit);
135
136 void CheckVehicleImpact();
137
138 void TryKillFromVehicle(AActor *OtherActor);
139
140 FTimerHandle VehicleSensorTimer;
141};
Base class for CARLA wheeled vehicles.
float VehicleBodyAllowance
Lateral clearance (cm) added on top of the capsule radius and sensor margin when testing a fast vehic...
Definition WalkerBase.h:75
float VehicleKillSpeed
A vehicle touching the walker while moving at least this fast (cm/s) kills it - ue4-dev parity,...
Definition WalkerBase.h:48
void SetTeleportDriven(bool bEnable)
Teleport-driven walkers (client-side crowd, replayer) skip overlap queries; the body mesh stays visib...
virtual void BeginPlay() override
float LifeSpanAfterDeath
Definition WalkerBase.h:31
FTimerHandle VehicleSensorTimer
Definition WalkerBase.h:140
TObjectPtr< USkeletalMeshComponent > WheelchairComponent
The wheelchair mesh attached by AttachWheelchair(), null for walkers spawned without one.
Definition WalkerBase.h:114
void StartDeathLifeSpan()
Definition WalkerBase.h:84
void TryKillFromVehicle(AActor *OtherActor)
float VehicleSensorPeriod
Vehicle proximity poll period in seconds.
Definition WalkerBase.h:68
bool bUsesWheelChair
Whether this walker was spawned riding a wheelchair (the "use_wheelchair" user attribute).
Definition WalkerBase.h:38
TArray< FSuspendedPrimitive > SuspendedPrimitives
Definition WalkerBase.h:130
float VehicleSensorSpeedBound
Fastest closing speed (cm/s) the proximity query is sized for (default 300 km/h).
Definition WalkerBase.h:81
AWalkerBase(const FObjectInitializer &ObjectInitializer)
float VehicleSensorMargin
How far beyond the capsule radius the vehicle proximity check reaches (cm).
Definition WalkerBase.h:62
void OnBodyHit(AActor *SelfActor, AActor *OtherActor, FVector NormalImpulse, const FHitResult &Hit)
void CheckVehicleImpact()
Collision state SetTeleportDriven() suspended, restored when the walker moves by itself again.
Definition WalkerBase.h:125
ECollisionEnabled::Type CollisionEnabled
Definition WalkerBase.h:127
TWeakObjectPtr< UPrimitiveComponent > Primitive
Definition WalkerBase.h:126