192{
193 if (IsValid(Character) == false)
194 {
195 return false;
196 }
197
199 UCapsuleComponent* CapsuleComponent = Character->GetCapsuleComponent();
200 UWorld* World = Character->GetWorld();
201 if (IsValid(MotionWarpingComponent) == false || IsValid(CapsuleComponent) == false || IsValid(World) == false)
202 {
203 return false;
204 }
205
206 FVector FacingDirection = IsValid(Instigator) ? Instigator->GetActorLocation() - Character->GetActorLocation() : Character->GetActorForwardVector();
207 FacingDirection.Z = 0.0f;
208
209 if (FacingDirection.Normalize() == false)
210 {
211 FacingDirection = Character->GetActorForwardVector();
212 FacingDirection.Z = 0.0f;
213 FacingDirection.Normalize();
214 }
215
216 const FVector KnockdownDirection = -FacingDirection;
217 const FVector SweepStart = CapsuleComponent->GetComponentLocation();
219
220
221 constexpr float CapsuleDecreaseValue = 2.0f;
222 const float CapsuleRadius = FMath::Max(CapsuleComponent->GetScaledCapsuleRadius() - CapsuleDecreaseValue , 1.0f);
223 const float CapsuleHalfHeight = FMath::Max(CapsuleComponent->GetScaledCapsuleHalfHeight() - CapsuleDecreaseValue , CapsuleRadius);
224 const FCollisionShape SweepShape = FCollisionShape::MakeCapsule(CapsuleRadius, CapsuleHalfHeight);
225
226
227 FCollisionObjectQueryParams ObjectQueryParams;
228 ObjectQueryParams.AddObjectTypesToQuery(ECC_WorldStatic);
229 ObjectQueryParams.AddObjectTypesToQuery(ECC_WorldDynamic);
230
231 FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(PlayerKnockdownMotionWarp), false, Character);
232 FHitResult HitResult;
233 const bool bBlockingHit = World->SweepSingleByObjectType(HitResult, SweepStart, SweepEnd,FQuat::Identity, ObjectQueryParams, SweepShape, QueryParams);
234
235
236 constexpr float WallTolerance = 10.0f;
237 const float AvailableDistance = bBlockingHit ? FMath::Max(HitResult.Distance - WallTolerance, 0.0f) :
KnockDownDistance;
238 const FVector WarpTargetLocation = Character->GetActorLocation() + KnockdownDirection * AvailableDistance;
239
241
242 return true;
243}
void UpdateMotionWarpTarget(FName WarpTargetName, const FVector &TargetLocation, const FRotator &TargetRotation, bool bRestart=false)
Definition CharacterMotionWarpingComponentBase.cpp:28