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