| 562 | } |
| 563 | |
| 564 | void UAlsxtCharacterMovementComponent::Prone(bool bClientSimulation) |
| 565 | { |
| 566 | if (!HasValidData()) |
| 567 | { |
| 568 | return; |
| 569 | } |
| 570 | |
| 571 | if (!bClientSimulation && !CanCrouchInCurrentState()) |
| 572 | { |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | // See if collision is already at desired size. |
| 577 | if (CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight() == GetProneHalfHeight()) |
| 578 | { |
| 579 | if (!bClientSimulation) |
| 580 | { |
| 581 | // CharacterOwner->SetIsProne(true); |
| 582 | } |
| 583 | CharacterOwner->OnStartCrouch( 0.f, 0.f ); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | if (bClientSimulation && CharacterOwner->GetLocalRole() == ROLE_SimulatedProxy) |
| 588 | { |
| 589 | // restore collision size before crouching |
| 590 | ACharacter* DefaultCharacter = CharacterOwner->GetClass()->GetDefaultObject<ACharacter>(); |
| 591 | CharacterOwner->GetCapsuleComponent()->SetCapsuleSize(DefaultCharacter->GetCapsuleComponent()->GetUnscaledCapsuleRadius(), DefaultCharacter->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight()); |
| 592 | bShrinkProxyCapsule = true; |
| 593 | } |
| 594 | |
| 595 | // Change collision size to prone dimensions |
| 596 | const float ComponentScale = CharacterOwner->GetCapsuleComponent()->GetShapeScale(); |
| 597 | const float OldUnscaledHalfHeight = CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight(); |
| 598 | const float OldUnscaledRadius = CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleRadius(); |
| 599 | // Height is not allowed to be smaller than radius. |
| 600 | const float ClampedProneHalfHeight = FMath::Max3(0.f, OldUnscaledRadius, GetProneHalfHeight()); |
| 601 | CharacterOwner->GetCapsuleComponent()->SetCapsuleSize(OldUnscaledRadius, ClampedProneHalfHeight); |
| 602 | float HalfHeightAdjust = (OldUnscaledHalfHeight - ClampedProneHalfHeight); |
| 603 | float ScaledHalfHeightAdjust = HalfHeightAdjust * ComponentScale; |
| 604 | |
| 605 | if( !bClientSimulation ) |
| 606 | { |
| 607 | // Crouching to a larger height? (this is rare) |
| 608 | if (ClampedProneHalfHeight > OldUnscaledHalfHeight) |
| 609 | { |
| 610 | FCollisionQueryParams CapsuleParams(SCENE_QUERY_STAT(CrouchTrace), false, CharacterOwner); |
| 611 | FCollisionResponseParams ResponseParam; |
| 612 | InitCollisionParams(CapsuleParams, ResponseParam); |
| 613 | const bool bEncroached = GetWorld()->OverlapBlockingTestByChannel(UpdatedComponent->GetComponentLocation() + ScaledHalfHeightAdjust * GetGravityDirection(), GetWorldToGravityTransform(), |
| 614 | UpdatedComponent->GetCollisionObjectType(), GetPawnCapsuleCollisionShape(SHRINK_None), CapsuleParams, ResponseParam); |
| 615 | |
| 616 | // If encroached, cancel |
| 617 | if( bEncroached ) |
| 618 | { |
| 619 | CharacterOwner->GetCapsuleComponent()->SetCapsuleSize(OldUnscaledRadius, OldUnscaledHalfHeight); |
| 620 | return; |
| 621 | } |
nothing calls this directly
no outgoing calls
no test coverage detected