61{
63 {
64 return;
65 }
66
69
70 if (CurrStart.Equals(CurrEnd, 1.0f))
71 {
72 return;
73 }
74
76 const FCollisionShape Shape = FCollisionShape::MakeSphere(
TraceRadius);
77
79 {
80 GetWorld()->SweepMultiByChannel(OutHits, CurrStart, CurrEnd, FQuat::Identity,
TraceChannel, Shape, Params);
81 }
82 else
83 {
84 const float StartMotion = FVector::Dist(
PrevStart, CurrStart);
85 const float EndMotion = FVector::Dist(
PrevEnd, CurrEnd);
86 const float MaxMotion = FMath::Max(StartMotion, EndMotion);
87
88 const float DesiredStepDist = FMath::Max(
TraceRadius * 0.5f, 5.0f);
89 const int32 Substeps = FMath::Clamp(FMath::CeilToInt(MaxMotion / DesiredStepDist), 1,
MaxSubsteps);
90
91 for (int32 i = 1; i <= Substeps; ++i)
92 {
93 const float T = (1.0f * i) / Substeps;
94 const FVector LerpStart = FMath::Lerp(
PrevStart, CurrStart, T);
95 const FVector LerpEnd = FMath::Lerp(
PrevEnd, CurrEnd, T);
96
97 TArray<FHitResult> SubHits;
98 GetWorld()->SweepMultiByChannel(SubHits, LerpStart, LerpEnd, FQuat::Identity,
TraceChannel, Shape, Params);
99 OutHits.Append(SubHits);
100 }
101
103 {
104 TArray<FHitResult> TrailStartHits;
106 {
107 GetWorld()->SweepMultiByChannel(TrailStartHits,
PrevStart, CurrStart, FQuat::Identity,
TraceChannel, Shape, Params);
108 }
109 OutHits.Append(TrailStartHits);
110
111 TArray<FHitResult> TrailEndHits;
112 GetWorld()->SweepMultiByChannel(TrailEndHits,
PrevEnd, CurrEnd, FQuat::Identity,
TraceChannel, Shape, Params);
113 OutHits.Append(TrailEndHits);
114
115#if ENABLE_DRAW_DEBUG
117 {
118 const FVector StartCenter = (
PrevStart + CurrStart) * 0.5f;
119 const float StartHalfHeight = (CurrStart -
PrevStart).Size() * 0.5f;
120 if (StartHalfHeight > KINDA_SMALL_NUMBER)
121 {
122 const FQuat StartRot = FRotationMatrix::MakeFromZ(CurrStart -
PrevStart).ToQuat();
123 const FColor StartColor = TrailStartHits.Num() > 0 ? FColor::Green : FColor::Cyan;
124 DrawDebugCapsule(GetWorld(), StartCenter, StartHalfHeight,
TraceRadius, StartRot, StartColor,
false, 0.5f);
125 }
126
127 const FVector EndCenter = (
PrevEnd + CurrEnd) * 0.5f;
128 const float EndHalfHeight = (CurrEnd -
PrevEnd).Size() * 0.5f;
129 if (EndHalfHeight > KINDA_SMALL_NUMBER)
130 {
131 const FQuat EndRot = FRotationMatrix::MakeFromZ(CurrEnd -
PrevEnd).ToQuat();
132 const FColor EndColor = TrailEndHits.Num() > 0 ? FColor::Green : FColor::Orange;
133 DrawDebugCapsule(GetWorld(), EndCenter, EndHalfHeight,
TraceRadius, EndRot, EndColor,
false, 0.5f);
134 }
135
136 DrawDebugLine(GetWorld(),
PrevStart,
PrevEnd, FColor::White,
false, 0.5f, 0, 1.0f);
137 DrawDebugLine(GetWorld(), CurrStart, CurrEnd, FColor::White, false, 0.5f, 0, 1.0f);
138 DrawDebugLine(GetWorld(),
PrevStart, CurrStart, FColor::Cyan,
false, 0.5f, 0, 1.5f);
139 DrawDebugLine(GetWorld(),
PrevEnd, CurrEnd, FColor::Orange,
false, 0.5f, 0, 1.5f);
140 }
141#endif
142 }
143 }
144
148}
ECollisionChannel TraceChannel
Definition TA_Trace.h:86
bool IsDebugEnabled() const
Definition TA_Trace.cpp:166
Definition TA_WeaponSphereTrace.h:20
FVector PrevEnd
Definition TA_WeaponSphereTrace.h:61
FName StartSocketName
Definition TA_WeaponSphereTrace.h:42
int32 MaxSubsteps
Definition TA_WeaponSphereTrace.h:54
TObjectPtr< USkeletalMeshComponent > TraceMeshComp
Definition TA_WeaponSphereTrace.h:67
bool bHasPrevPos
Definition TA_WeaponSphereTrace.h:63
uint8 bUseSubstepSweep
Definition TA_WeaponSphereTrace.h:51
bool bTraceSocketReady
Definition TA_WeaponSphereTrace.h:62
FName EndSocketName
Definition TA_WeaponSphereTrace.h:45
uint8 bAddTrailSweeps
Definition TA_WeaponSphereTrace.h:57
FVector PrevStart
Definition TA_WeaponSphereTrace.h:60