50 USkeletalMeshComponent *WalkerMesh = GetMesh();
51 if (WalkerMesh ==
nullptr)
53 UE_LOG(LogCarla, Warning,
54 TEXT(
"Wheelchair: walker %s has no mesh, spawning as normal pedestrian"),
61 auto *ChairMesh = Cast<USkeletalMesh>(FSoftObjectPath(
62 TEXT(
"/Game/Carla/Static/Pedestrian/Prop_Wheelchair/Meshes_/SM_Wheelchair.SM_Wheelchair"))
64 auto *SittingAnim = Cast<UAnimSequence>(FSoftObjectPath(
65 TEXT(
"/Game/Carla/Static/Pedestrian/Animations/WheelchairUser/WheelchairSitting_Moving2.WheelchairSitting_Moving2"))
67 if (ChairMesh ==
nullptr || SittingAnim ==
nullptr)
69 UE_LOG(LogCarla, Warning,
70 TEXT(
"Wheelchair: content not available (mesh=%d anim=%d), walker %s stays a normal pedestrian"),
71 ChairMesh !=
nullptr, SittingAnim !=
nullptr, *GetName());
87 WalkerMesh, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
100 constexpr float RiderDrop = 25.0f;
101 WalkerMesh->AddLocalOffset(FVector(0.0f, 0.0f, -RiderDrop));
107 const TCHAR *ChairAnimMode = TEXT(
"none");
108 auto *ChairAnimClass = Cast<UClass>(FSoftObjectPath(
109 TEXT(
"/Game/Carla/Static/Pedestrian/Animations/Wheelchair/ABP_WheelChair_MK.ABP_WheelChair_MK_C"))
111 if (ChairAnimClass !=
nullptr && !ChairAnimClass->HasAnyClassFlags(CLASS_NewerVersionExists))
114 ChairAnimMode = TEXT(
"ABP_WheelChair_MK");
116 else if (
auto *RollingAnim = Cast<UAnimSequence>(FSoftObjectPath(
117 TEXT(
"/Game/Carla/Static/Pedestrian/Animations/Wheelchair/Wheelchair_Rolling.Wheelchair_Rolling"))
121 ChairAnimMode = TEXT(
"Wheelchair_Rolling loop");
129 WalkerMesh->PlayAnimation(SittingAnim,
true);
133 UE_LOG(LogCarla, Display,
134 TEXT(
"Wheelchair attached to walker %s (chair anim: %s, rider anim: WheelchairSitting_Moving2 loop)"),
135 *GetName(), ChairAnimMode);
158 TArray<UPrimitiveComponent *> Primitives;
159 GetComponents<UPrimitiveComponent>(Primitives,
false);
160 for (UPrimitiveComponent *Primitive : Primitives)
162 const ECollisionEnabled::Type Enabled = Primitive->GetCollisionEnabled();
163 if (Enabled == ECollisionEnabled::QueryAndPhysics)
165 Primitive->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
167 else if (Enabled == ECollisionEnabled::PhysicsOnly)
169 Primitive->SetCollisionEnabled(ECollisionEnabled::NoCollision);
177 if (Primitive->GetCollisionObjectType() == ECC_WorldDynamic)
179 Primitive->SetCollisionObjectType(ECC_Pawn);
184 if (USkeletalMeshComponent *BodyMesh = GetMesh())
186 BodyMesh->SetGenerateOverlapEvents(
false);
187 BodyMesh->bUpdateOverlapsOnAnimationFinalize =
false;
193 TArray<UPrimitiveComponent *> Primitives;
194 GetComponents<UPrimitiveComponent>(Primitives,
false);
195 for (UPrimitiveComponent *Primitive : Primitives)
197 Primitive->SetGenerateOverlapEvents(
false);
209 GetWorldTimerManager().SetTimer(
220 if (Suspended.Primitive.IsValid())
222 Suspended.Primitive->SetCollisionEnabled(Suspended.CollisionEnabled);
223 Suspended.Primitive->SetGenerateOverlapEvents(Suspended.bGenerateOverlapEvents);
233 TArray<UPrimitiveComponent *> Primitives;
234 GetComponents<UPrimitiveComponent>(Primitives,
false);
235 for (UPrimitiveComponent *Primitive : Primitives)
238 if (Primitive->GetCollisionResponseToChannel(ECC_GameTraceChannel2 ) == ECR_Block)
242 SuspendedPrimitives.Add({Primitive, Primitive->BodyInstance.GetCollisionEnabled(
false), Primitive->GetGenerateOverlapEvents()});
243 Primitive->SetGenerateOverlapEvents(
false);
244 Primitive->SetCollisionEnabled(ECollisionEnabled::NoCollision);
288 const UCapsuleComponent *Capsule = GetCapsuleComponent();
289 if (Capsule ==
nullptr)
294 const float HalfHeight = Capsule->GetScaledCapsuleHalfHeight();
306 const float QueryRadius =
309 TArray<FOverlapResult> Overlaps;
310 FCollisionObjectQueryParams ObjectParams;
311 ObjectParams.AddObjectTypesToQuery(ECC_Vehicle);
312 FCollisionQueryParams Params(SCENE_QUERY_STAT(WalkerVehicleSensor),
false,
this);
313 if (!GetWorld()->OverlapMultiByObjectType(
318 FCollisionShape::MakeCapsule(QueryRadius, HalfHeight),
324 const FVector WalkerLoc = GetActorLocation();
325 for (
const FOverlapResult &Overlap : Overlaps)
328 UPrimitiveComponent *VehicleBody = Overlap.GetComponent();
329 if (
Vehicle ==
nullptr || VehicleBody ==
nullptr)
333 const FVector Velocity =
Vehicle->GetVelocity();
334 const float Speed = Velocity.Size();
342 const float DistToBody =
343 VehicleBody->GetDistanceToCollision(WalkerLoc, OnBody);
344 bool bKill = DistToBody >= 0.0f && DistToBody <= ContactRadius;
350 const FVector PathEnd = FVector(
Vehicle->GetActorLocation()) + Velocity * Dt * 1.25f;
351 const FVector Closest = FMath::ClosestPointOnSegment(
352 WalkerLoc,
Vehicle->GetActorLocation(), PathEnd);
353 bKill = FVector::Dist2D(Closest, WalkerLoc) <=
355 FMath::Abs(Closest.Z - WalkerLoc.Z) <= HalfHeight + 200.0f;
376 if (
auto *WalkerController = Cast<AWalkerController>(GetController()))
378 WalkerController->StopNavigation();
381 if (
auto *Movement = GetCharacterMovement())
383 Movement->StopMovementImmediately();
384 Movement->DisableMovement();
392 if (
auto *Capsule = GetCapsuleComponent())
394 Capsule->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Ignore);
401 if (Killer !=
nullptr)
403 FHitResult FakeHit(ForceInit);
404 FakeHit.HitObjectHandle = FActorInstanceHandle(
this);
405 FakeHit.ImpactPoint = GetActorLocation();
406 FakeHit.ImpactNormal = (-ImpactVelocity).GetSafeNormal();
407 Killer->OnActorHit.Broadcast(Killer,
this,
408 ImpactVelocity * 100.0f , FakeHit);
411 USkeletalMeshComponent *BodyMesh = GetMesh();
412 bool bDeterministic =
true;
415 bDeterministic = Episode->GetSettings().bDeterministicRagdolls;
418 if (BodyMesh !=
nullptr && !bDeterministic)
425 BodyMesh->SetCollisionProfileName(TEXT(
"Ragdoll"));
426 BodyMesh->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Ignore);
427 BodyMesh->SetSimulatePhysics(
true);
428 BodyMesh->SetAllPhysicsLinearVelocity(ImpactVelocity,
false);
430 else if (BodyMesh !=
nullptr)
435 const FVector LocalDir =
436 GetActorTransform().InverseTransformVectorNoScale(
437 ImpactVelocity.GetSafeNormal2D());
438 const TCHAR *AnimName;
439 if (FMath::Abs(LocalDir.X) >= FMath::Abs(LocalDir.Y))
442 AnimName = LocalDir.X >= 0.0f
443 ? TEXT(
"/Game/Carla/Animations/Death_Anim/Anim_Death_F_01.Anim_Death_F_01")
444 : TEXT(
"/Game/Carla/Animations/Death_Anim/Anim_Death_B_01.Anim_Death_B_01");
448 AnimName = LocalDir.Y >= 0.0f
449 ? TEXT(
"/Game/Carla/Animations/Death_Anim/Anim_Death_R_01.Anim_Death_R_01")
450 : TEXT(
"/Game/Carla/Animations/Death_Anim/Anim_Death_L_01.Anim_Death_L_01");
452 if (
auto *DeathAnim = Cast<UAnimSequence>(
453 StaticLoadObject(UAnimSequence::StaticClass(),
nullptr, AnimName)))
455 BodyMesh->PlayAnimation(DeathAnim,
false);
459 UE_LOG(LogCarla, Warning,
460 TEXT(
"Walker %s: death animation '%s' not found, using ragdoll"),
461 *GetName(), AnimName);
462 BodyMesh->SetCollisionProfileName(TEXT(
"Ragdoll"));
463 BodyMesh->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Ignore);
464 BodyMesh->SetSimulatePhysics(
true);
465 BodyMesh->SetAllPhysicsLinearVelocity(ImpactVelocity,
false);
472 if (BodyMesh !=
nullptr && !BodyMesh->IsSimulatingPhysics())
474 BodyMesh->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Ignore);
477 UE_LOG(LogCarla, Log, TEXT(
"Walker %s killed by vehicle impact (%.0f cm/s)"),
478 *GetName(), ImpactVelocity.Size());
void Kill(FVector ImpactVelocity, AActor *Killer=nullptr)
Kill the walker as if run over: stop navigation and movement, stop blocking vehicles,...