Advertisement
Davixe

CharacterMovementComponent (GravityVersion UE4.9)

Sep 12th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 115.52 KB | None | 0 0
  1. // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
  2.  
  3. #pragma once
  4. #include "AI/Navigation/NavigationAvoidanceTypes.h"
  5. #include "AI/RVOAvoidanceInterface.h"
  6. #include "Animation/AnimationAsset.h"
  7. #include "Engine/EngineBaseTypes.h"
  8. #include "Engine/EngineTypes.h"
  9. #include "GameFramework/PawnMovementComponent.h"
  10. #include "Interfaces/NetworkPredictionInterface.h"
  11. #include "WorldCollision.h"
  12. #include "CharacterMovementComponent.generated.h"
  13.  
  14. class FDebugDisplayInfo;
  15. class ACharacter;
  16.  
  17. /** Data about the floor for walking movement, used by CharacterMovementComponent. */
  18. USTRUCT(BlueprintType)
  19. struct ENGINE_API FFindFloorResult
  20. {
  21.     GENERATED_USTRUCT_BODY()
  22.  
  23.         /** True if there was a blocking hit in the floor test. */
  24.         UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = CharacterFloor)
  25.         uint32 bBlockingHit : 1;
  26.  
  27.     /** True if the hit found a valid walkable floor. */
  28.     UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = CharacterFloor)
  29.         uint32 bWalkableFloor : 1;
  30.  
  31.     /** True if the hit found a valid walkable floor using a line trace (rather than a sweep test, which happens when the sweep test fails to yield a walkable surface). */
  32.     UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = CharacterFloor)
  33.         uint32 bLineTrace : 1;
  34.  
  35.     /** The distance to the floor, computed from the swept capsule trace. */
  36.     UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = CharacterFloor)
  37.         float FloorDist;
  38.  
  39.     /** The distance to the floor, computed from the trace. Only valid if bLineTrace is true. */
  40.     UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = CharacterFloor)
  41.         float LineDist;
  42.  
  43.     /** Hit result of the test that found a floor. Includes more specific data about the point of impact and surface normal at that point. */
  44.     UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = CharacterFloor)
  45.         FHitResult HitResult;
  46.  
  47. public:
  48.  
  49.     FFindFloorResult()
  50.         : bBlockingHit(false)
  51.         , bWalkableFloor(false)
  52.         , bLineTrace(false)
  53.         , FloorDist(0.f)
  54.         , LineDist(0.f)
  55.         , HitResult(1.f)
  56.     {
  57.     }
  58.  
  59.     /** Returns true if the floor result hit a walkable surface. */
  60.     bool IsWalkableFloor() const
  61.     {
  62.         return bBlockingHit && bWalkableFloor;
  63.     }
  64.  
  65.     void Clear()
  66.     {
  67.         bBlockingHit = false;
  68.         bWalkableFloor = false;
  69.         bLineTrace = false;
  70.         FloorDist = 0.f;
  71.         LineDist = 0.f;
  72.         HitResult.Reset(1.f, false);
  73.     }
  74.  
  75.     void SetFromSweep(const FHitResult& InHit, const float InSweepFloorDist, const bool bIsWalkableFloor);
  76.     void SetFromLineTrace(const FHitResult& InHit, const float InSweepFloorDist, const float InLineDist, const bool bIsWalkableFloor);
  77. };
  78.  
  79. /**
  80. * Tick function that calls UCharacterMovementComponent::PreClothTick
  81. **/
  82. USTRUCT()
  83. struct FCharacterMovementComponentPreClothTickFunction : public FTickFunction
  84. {
  85.     GENERATED_USTRUCT_BODY()
  86.  
  87.         /** CharacterMovementComponent that is the target of this tick **/
  88.     class UCharacterMovementComponent* Target;
  89.  
  90.     /**
  91.     * Abstract function actually execute the tick.
  92.     * @param DeltaTime - frame time to advance, in seconds
  93.     * @param TickType - kind of tick for this frame
  94.     * @param CurrentThread - thread we are executing on, useful to pass along as new tasks are created
  95.     * @param MyCompletionGraphEvent - completion event for this task. Useful for holding the completion of this task until certain child tasks are complete.
  96.     **/
  97.     virtual void ExecuteTick(float DeltaTime, enum ELevelTick TickType, ENamedThreads::Type CurrentThread, const FGraphEventRef& MyCompletionGraphEvent) override;
  98.  
  99.     /** Abstract function to describe this tick. Used to print messages about illegal cycles in the dependency graph **/
  100.     virtual FString DiagnosticMessage() override;
  101. };
  102.  
  103. /** Shared pointer for easy memory management of FSavedMove_Character, for accumulating and replaying network moves. */
  104. typedef TSharedPtr<class FSavedMove_Character> FSavedMovePtr;
  105.  
  106.  
  107. //=============================================================================
  108. /**
  109. * CharacterMovementComponent handles movement logic for the associated Character owner.
  110. * It supports various movement modes including: walking, falling, swimming, flying, custom.
  111. *
  112. * Movement is affected primarily by current Velocity and Acceleration. Acceleration is updated each frame
  113. * based on the input vector accumulated thus far (see UPawnMovementComponent::GetPendingInputVector()).
  114. *
  115. * Networking is fully implemented, with server-client correction and prediction included.
  116. *
  117. * @see ACharacter, UPawnMovementComponent
  118. * @see https://docs.unrealengine.com/latest/INT/Gameplay/Framework/Pawn/Character/
  119. */
  120.  
  121. UCLASS()
  122. class ENGINE_API UCharacterMovementComponent : public UPawnMovementComponent, public IRVOAvoidanceInterface, public INetworkPredictionInterface
  123. {
  124.     GENERATED_BODY()
  125. public:
  126.  
  127.     /**
  128.     * Default UObject constructor.
  129.     */
  130.     UCharacterMovementComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
  131.  
  132. protected:
  133.  
  134.     /** Character movement component belongs to */
  135.     UPROPERTY()
  136.         ACharacter* CharacterOwner;
  137.  
  138. public:
  139.  
  140.     /** Custom gravity scale. Gravity is multiplied by this amount for the character. */
  141.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite)
  142.         float GravityScale;
  143.  
  144.     /** Maximum height character can step up */
  145.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  146.         float MaxStepHeight;
  147.  
  148.     /** Initial velocity (instantaneous vertical acceleration) when jumping. */
  149.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (DisplayName = "Jump Z Velocity", ClampMin = "0", UIMin = "0"))
  150.         float JumpZVelocity;
  151.  
  152.     /** Fraction of JumpZVelocity to use when automatically "jumping off" of a base actor that's not allowed to be a base for a character. (For example, if you're not allowed to stand on other players.) */
  153.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, AdvancedDisplay, meta = (ClampMin = "0", UIMin = "0"))
  154.         float JumpOffJumpZFactor;
  155.  
  156. private:
  157.  
  158.     /**
  159.     * Max angle in degrees of a walkable surface. Any greater than this and it is too steep to be walkable.
  160.     */
  161.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, meta = (ClampMin = "0.0", ClampMax = "90.0", UIMin = "0.0", UIMax = "90.0"))
  162.         float WalkableFloorAngle;
  163.  
  164.     /**
  165.     * Minimum Z value for floor normal. If less, not a walkable surface. Computed from WalkableFloorAngle.
  166.     */
  167.     UPROPERTY(Category = "Character Movement: Walking", VisibleAnywhere)
  168.         float WalkableFloorZ;
  169.  
  170. public:
  171.  
  172.     /**
  173.     * Actor's current movement mode (walking, falling, etc).
  174.     *    - walking:  Walking on a surface, under the effects of friction, and able to "step up" barriers. Vertical velocity is zero.
  175.     *    - falling:  Falling under the effects of gravity, after jumping or walking off the edge of a surface.
  176.     *    - flying:   Flying, ignoring the effects of gravity.
  177.     *    - swimming: Swimming through a fluid volume, under the effects of gravity and buoyancy.
  178.     *    - custom:   User-defined custom movement mode, including many possible sub-modes.
  179.     * This is automatically replicated through the Character owner and for client-server movement functions.
  180.     * @see SetMovementMode(), CustomMovementMode
  181.     */
  182.     UPROPERTY(Category = "Character Movement: MovementMode", BlueprintReadOnly)
  183.         TEnumAsByte<enum EMovementMode> MovementMode;
  184.  
  185.     /**
  186.     * Current custom sub-mode if MovementMode is set to Custom.
  187.     * This is automatically replicated through the Character owner and for client-server movement functions.
  188.     * @see SetMovementMode()
  189.     */
  190.     UPROPERTY(Category = "Character Movement: MovementMode", BlueprintReadOnly)
  191.         uint8 CustomMovementMode;
  192.  
  193.     /** Saved location of object we are standing on, for UpdateBasedMovement() to determine if base moved in the last frame, and therefore pawn needs an update. */
  194.     FVector OldBaseLocation;
  195.  
  196.     /** Saved location of object we are standing on, for UpdateBasedMovement() to determine if base moved in the last frame, and therefore pawn needs an update. */
  197.     FQuat OldBaseQuat;
  198.  
  199.     /**
  200.     * Setting that affects movement control. Higher values allow faster changes in direction.
  201.     * If bUseSeparateBrakingFriction is false, also affects the ability to stop more quickly when braking (whenever Acceleration is zero), where it is multiplied by BrakingFrictionFactor.
  202.     * When braking, this property allows you to control how much friction is applied when moving across the ground, applying an opposing force that scales with current velocity.
  203.     * This can be used to simulate slippery surfaces such as ice or oil by changing the value (possibly based on the material pawn is standing on).
  204.     * @see BrakingDecelerationWalking, BrakingFriction, bUseSeparateBrakingFriction, BrakingFrictionFactor
  205.     */
  206.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  207.         float GroundFriction;
  208.  
  209.     /** The maximum ground speed when walking. Also determines maximum lateral speed when falling. */
  210.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  211.         float MaxWalkSpeed;
  212.  
  213.     /** The maximum ground speed when walking and crouched. */
  214.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  215.         float MaxWalkSpeedCrouched;
  216.  
  217.     /** The maximum swimming speed. */
  218.     UPROPERTY(Category = "Character Movement: Swimming", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  219.         float MaxSwimSpeed;
  220.  
  221.     /** The maximum flying speed. */
  222.     UPROPERTY(Category = "Character Movement: Flying", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  223.         float MaxFlySpeed;
  224.  
  225.     /** The maximum speed when using Custom movement mode. */
  226.     UPROPERTY(Category = "Character Movement: Custom Movement", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  227.         float MaxCustomMovementSpeed;
  228.  
  229.     /** Max Acceleration (rate of change of velocity) */
  230.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  231.         float MaxAcceleration;
  232.  
  233.     /**
  234.     * Factor used to multiply actual value of friction used when braking.
  235.     * This applies to any friction value that is currently used, which may depend on bUseSeparateBrakingFriction.
  236.     * @note This is 2 by default for historical reasons, a value of 1 gives the true drag equation.
  237.     * @see bUseSeparateBrakingFriction, GroundFriction, BrakingFriction
  238.     */
  239.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  240.         float BrakingFrictionFactor;
  241.  
  242.     /**
  243.     * Friction (drag) coefficient applied when braking (whenever Acceleration = 0, or if character is exceeding max speed); actual value used is this multiplied by BrakingFrictionFactor.
  244.     * When braking, this property allows you to control how much friction is applied when moving across the ground, applying an opposing force that scales with current velocity.
  245.     * Braking is composed of friction (velocity-dependent drag) and constant deceleration.
  246.     * This is the current value, used in all movement modes; if this is not desired, override it or bUseSeparateBrakingFriction when movement mode changes.
  247.     * @note Only used if bUseSeparateBrakingFriction setting is true, otherwise current friction such as GroundFriction is used.
  248.     * @see bUseSeparateBrakingFriction, BrakingFrictionFactor, GroundFriction, BrakingDecelerationWalking
  249.     */
  250.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0", EditCondition = "bUseSeparateBrakingFriction"))
  251.         float BrakingFriction;
  252.  
  253.     /**
  254.     * If true, BrakingFriction will be used to slow the character to a stop (when there is no Acceleration).
  255.     * If false, braking uses the same friction passed to CalcVelocity() (ie GroundFriction when walking), multiplied by BrakingFrictionFactor.
  256.     * This setting applies to all movement modes; if only desired in certain modes, consider toggling it when movement modes change.
  257.     * @see BrakingFriction
  258.     */
  259.     UPROPERTY(Category = "Character Movement (General Settings)", EditDefaultsOnly, BlueprintReadWrite)
  260.         uint32 bUseSeparateBrakingFriction : 1;
  261.  
  262.     /**
  263.     * Deceleration when walking and not applying acceleration. This is a constant opposing force that directly lowers velocity by a constant value.
  264.     * @see GroundFriction, MaxAcceleration
  265.     */
  266.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  267.         float BrakingDecelerationWalking;
  268.  
  269.     /**
  270.     * Lateral deceleration when falling and not applying acceleration.
  271.     * @see MaxAcceleration
  272.     */
  273.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  274.         float BrakingDecelerationFalling;
  275.  
  276.     /**
  277.     * Deceleration when swimming and not applying acceleration.
  278.     * @see MaxAcceleration
  279.     */
  280.     UPROPERTY(Category = "Character Movement: Swimming", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  281.         float BrakingDecelerationSwimming;
  282.  
  283.     /**
  284.     * Deceleration when flying and not applying acceleration.
  285.     * @see MaxAcceleration
  286.     */
  287.     UPROPERTY(Category = "Character Movement: Flying", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  288.         float BrakingDecelerationFlying;
  289.  
  290.     /**
  291.     * When falling, amount of lateral movement control available to the character.
  292.     * 0 = no control, 1 = full control at max speed of MaxWalkSpeed.
  293.     */
  294.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  295.         float AirControl;
  296.  
  297.     /**
  298.     * When falling, multiplier applied to AirControl when lateral velocity is less than AirControlBoostVelocityThreshold.
  299.     * Setting this to zero will disable air control boosting. Final result is clamped at 1.
  300.     */
  301.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  302.         float AirControlBoostMultiplier;
  303.  
  304.     /**
  305.     * When falling, if lateral velocity magnitude is less than this value, AirControl is multiplied by AirControlBoostMultiplier.
  306.     * Setting this to zero will disable air control boosting.
  307.     */
  308.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  309.         float AirControlBoostVelocityThreshold;
  310.  
  311.     /**
  312.     * Friction to apply to lateral air movement when falling.
  313.     * If bUseSeparateBrakingFriction is false, also affects the ability to stop more quickly when braking (whenever Acceleration is zero).
  314.     * @see BrakingFriction, bUseSeparateBrakingFriction
  315.     */
  316.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  317.         float FallingLateralFriction;
  318.  
  319.     /** Collision half-height when crouching (component scale is applied separately) */
  320.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadOnly, meta = (ClampMin = "0", UIMin = "0"))
  321.         float CrouchedHalfHeight;
  322.  
  323.     /** Water buoyancy. A ratio (1.0 = neutral buoyancy, 0.0 = no buoyancy) */
  324.     UPROPERTY(Category = "Character Movement: Swimming", EditAnywhere, BlueprintReadWrite)
  325.         float Buoyancy;
  326.  
  327.     /**
  328.     * Don't allow the character to perch on the edge of a surface if the contact is this close to the edge of the capsule.
  329.     * Note that characters will not fall off if they are within MaxStepHeight of a walkable surface below.
  330.     */
  331.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, AdvancedDisplay, meta = (ClampMin = "0", UIMin = "0"))
  332.         float PerchRadiusThreshold;
  333.  
  334.     /**
  335.     * When perching on a ledge, add this additional distance to MaxStepHeight when determining how high above a walkable floor we can perch.
  336.     * Note that we still enforce MaxStepHeight to start the step up; this just allows the character to hang off the edge or step slightly higher off the floor.
  337.     * (@see PerchRadiusThreshold)
  338.     */
  339.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, AdvancedDisplay, meta = (ClampMin = "0", UIMin = "0"))
  340.         float PerchAdditionalHeight;
  341.  
  342.     /** Change in rotation per second, used when UseControllerDesiredRotation or OrientRotationToMovement are true. */
  343.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite)
  344.         FRotator RotationRate;
  345.  
  346.     /** If true, smoothly rotate the Character toward the Controller's desired rotation, using RotationRate as the rate of rotation change. Overridden by OrientRotationToMovement. */
  347.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  348.         uint32 bUseControllerDesiredRotation : 1;
  349.  
  350.     /**
  351.     * If true, rotate the Character toward the direction of acceleration, using RotationRate as the rate of rotation change. Overrides UseControllerDesiredRotation.
  352.     * Normally you will want to make sure that other settings are cleared, such as bUseControllerRotationYaw on the Character.
  353.     */
  354.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite)
  355.         uint32 bOrientRotationToMovement : 1;
  356.  
  357. protected:
  358.  
  359.     /**
  360.     * True during movement update.
  361.     * Used internally so that attempts to change CharacterOwner and UpdatedComponent are deferred until after an update.
  362.     * @see IsMovementInProgress()
  363.     */
  364.     UPROPERTY()
  365.         uint32 bMovementInProgress : 1;
  366.  
  367. public:
  368.  
  369.     /**
  370.     * If true, high-level movement updates will be wrapped in a movement scope that accumulates updates and defers a bulk of the work until the end.
  371.     * When enabled, touch and hit events will not be triggered until the end of multiple moves within an update, which can improve performance.
  372.     *
  373.     * @see FScopedMovementUpdate
  374.     */
  375.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, AdvancedDisplay)
  376.         uint32 bEnableScopedMovementUpdates : 1;
  377.  
  378.     /** Ignores size of acceleration component, and forces max acceleration to drive character at full velocity. */
  379.     UPROPERTY()
  380.         uint32 bForceMaxAccel : 1;
  381.  
  382.     /**
  383.     * If true, movement will be performed even if there is no Controller for the Character owner.
  384.     * Normally without a Controller, movement will be aborted and velocity and acceleration are zeroed if the character is walking.
  385.     * Characters that are spawned without a Controller but with this flag enabled will initialize the movement mode to DefaultLandMovementMode or DefaultWaterMovementMode appropriately.
  386.     * @see DefaultLandMovementMode, DefaultWaterMovementMode
  387.     */
  388.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  389.         uint32 bRunPhysicsWithNoController : 1;
  390.  
  391.     /**
  392.     * Force the Character in MOVE_Walking to do a check for a valid floor even if he hasn't moved. Cleared after next floor check.
  393.     * Normally if bAlwaysCheckFloor is false we try to avoid the floor check unless some conditions are met, but this can be used to force the next check to always run.
  394.     */
  395.     UPROPERTY(Category = "Character Movement: Walking", VisibleInstanceOnly, BlueprintReadWrite, AdvancedDisplay)
  396.         uint32 bForceNextFloorCheck : 1;
  397.  
  398.     /** If true, the capsule needs to be shrunk on this simulated proxy, to avoid replication rounding putting us in geometry.
  399.     * Whenever this is set to true, this will cause the capsule to be shrunk again on the next update, and then set to false. */
  400.     UPROPERTY()
  401.         uint32 bShrinkProxyCapsule : 1;
  402.  
  403.     /** If true, Character can walk off a ledge. */
  404.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite)
  405.         uint32 bCanWalkOffLedges : 1;
  406.  
  407.     /** If true, Character can walk off a ledge when crouching. */
  408.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite)
  409.         uint32 bCanWalkOffLedgesWhenCrouching : 1;
  410.  
  411. public:
  412.  
  413.     /** true to update CharacterOwner and UpdatedComponent after movement ends */
  414.     UPROPERTY()
  415.         uint32 bDeferUpdateMoveComponent : 1;
  416.  
  417.     /** What to update CharacterOwner and UpdatedComponent after movement ends */
  418.     UPROPERTY()
  419.         USceneComponent* DeferredUpdatedMoveComponent;
  420.  
  421.     /** Maximum step height for getting out of water */
  422.     UPROPERTY(Category = "Character Movement: Swimming", EditAnywhere, BlueprintReadWrite, AdvancedDisplay, meta = (ClampMin = "0", UIMin = "0"))
  423.         float MaxOutOfWaterStepHeight;
  424.  
  425.     /** Z velocity applied when pawn tries to get out of water */
  426.     UPROPERTY(Category = "Character Movement: Swimming", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  427.         float OutofWaterZ;
  428.  
  429.     /** Mass of pawn (for when momentum is imparted to it). */
  430.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0", UIMin = "0"))
  431.         float Mass;
  432.  
  433.     /** If enabled, the player will interact with physics objects when walking into them. */
  434.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite)
  435.         bool bEnablePhysicsInteraction;
  436.  
  437.     /** If enabled, the TouchForceFactor is applied per kg mass of the affected object. */
  438.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  439.         bool bTouchForceScaledToMass;
  440.  
  441.     /** If enabled, the PushForceFactor is applied per kg mass of the affected object. */
  442.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  443.         bool bPushForceScaledToMass;
  444.  
  445.     /** If enabled, the applied push force will try to get the physics object to the same velocity than the player, not faster. This will only
  446.     scale the force down, it will never apply more force than defined by PushForceFactor. */
  447.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  448.         bool bScalePushForceToVelocity;
  449.  
  450.     /** Force applied to objects we stand on (due to Mass and Gravity) is scaled by this amount. */
  451.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  452.         float StandingDownwardForceScale;
  453.  
  454.     /** Initial impulse force to apply when the player bounces into a blocking physics object. */
  455.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  456.         float InitialPushForceFactor;
  457.  
  458.     /** Force to apply when the player collides with a blocking physics object. */
  459.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  460.         float PushForceFactor;
  461.  
  462.     /** Z-Offset for the position the force is applied to. 0.0f is the center of the physics object, 1.0f is the top and -1.0f is the bottom of the object. */
  463.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (UIMin = "-1.0", UIMax = "1.0"), meta = (editcondition = "bEnablePhysicsInteraction"))
  464.         float PushForcePointZOffsetFactor;
  465.  
  466.     /** Force to apply to physics objects that are touched by the player. */
  467.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  468.         float TouchForceFactor;
  469.  
  470.     /** Minimum Force applied to touched physics objects. If < 0.0f, there is no minimum. */
  471.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  472.         float MinTouchForce;
  473.  
  474.     /** Maximum force applied to touched physics objects. If < 0.0f, there is no maximum. */
  475.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  476.         float MaxTouchForce;
  477.  
  478.     /** Force per kg applied constantly to all overlapping components. */
  479.     UPROPERTY(Category = "Character Movement: Physics Interaction", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bEnablePhysicsInteraction"))
  480.         float RepulsionForce;
  481.  
  482.  
  483. public:
  484.     // Deprecated properties
  485.  
  486.     UPROPERTY()
  487.         uint32 bForceBraking_DEPRECATED : 1;
  488.  
  489.     /** Multiplier to max ground speed to use when crouched */
  490.     UPROPERTY()
  491.         float CrouchedSpeedMultiplier_DEPRECATED;
  492.  
  493.     UPROPERTY()
  494.         float UpperImpactNormalScale_DEPRECATED;
  495.  
  496. protected:
  497.  
  498.     /**
  499.     * Current acceleration vector (with magnitude).
  500.     * This is calculated each update based on the input vector and the constraints of MaxAcceleration and the current movement mode.
  501.     */
  502.     UPROPERTY()
  503.         FVector Acceleration;
  504.  
  505.     /**
  506.     * Location after last PerformMovement update. Used internally to detect changes in position from outside character movement to try to validate the current floor.
  507.     */
  508.     UPROPERTY()
  509.         FVector LastUpdateLocation;
  510.  
  511.     /** Accumulated impulse to be added next tick. */
  512.     UPROPERTY()
  513.         FVector PendingImpulseToApply;
  514.  
  515.     /** Accumulated force to be added next tick. */
  516.     UPROPERTY()
  517.         FVector PendingForceToApply;
  518.  
  519.     /**
  520.     * Modifier to applied to values such as acceleration and max speed due to analog input.
  521.     */
  522.     UPROPERTY()
  523.         float AnalogInputModifier;
  524.  
  525.     /** Computes the analog input modifier based on current input vector and/or acceleration. */
  526.     virtual float ComputeAnalogInputModifier() const;
  527.  
  528. public:
  529.  
  530.     /**
  531.     * Compute remaining time step given remaining time and current iterations.
  532.     * The last iteration (limited by MaxSimulationIterations) always returns the remaining time, which may violate MaxSimulationTimeStep.
  533.     *
  534.     * @param RemainingTime      Remaining time in the tick.
  535.     * @param Iterations     Current iteration of the tick (starting at 1).
  536.     * @return The remaining time step to use for the next sub-step of iteration.
  537.     * @see MaxSimulationTimeStep, MaxSimulationIterations
  538.     */
  539.     float GetSimulationTimeStep(float RemainingTime, int32 Iterations) const;
  540.  
  541.     /**
  542.     * Max time delta for each discrete simulation step.
  543.     * Used primarily in the the more advanced movement modes that break up larger time steps (usually those applying gravity such as falling and walking).
  544.     * Lowering this value can address issues with fast-moving objects or complex collision scenarios, at the cost of performance.
  545.     *
  546.     * WARNING: if (MaxSimulationTimeStep * MaxSimulationIterations) is too low for the min framerate, the last simulation step may exceed MaxSimulationTimeStep to complete the simulation.
  547.     * @see MaxSimulationIterations
  548.     */
  549.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, AdvancedDisplay, meta = (ClampMin = "0.0166", ClampMax = "0.50", UIMin = "0.0166", UIMax = "0.50"))
  550.         float MaxSimulationTimeStep;
  551.  
  552.     /**
  553.     * Max number of iterations used for each discrete simulation step.
  554.     * Used primarily in the the more advanced movement modes that break up larger time steps (usually those applying gravity such as falling and walking).
  555.     * Increasing this value can address issues with fast-moving objects or complex collision scenarios, at the cost of performance.
  556.     *
  557.     * WARNING: if (MaxSimulationTimeStep * MaxSimulationIterations) is too low for the min framerate, the last simulation step may exceed MaxSimulationTimeStep to complete the simulation.
  558.     * @see MaxSimulationTimeStep
  559.     */
  560.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, AdvancedDisplay, meta = (ClampMin = "1", ClampMax = "25", UIMin = "1", UIMax = "25"))
  561.         int32 MaxSimulationIterations;
  562.  
  563.     /**
  564.     * How long to take to smoothly interpolate from the old pawn position on the client to the corrected one sent by the server.
  565.     */
  566.     UPROPERTY(Category = "Character Movement (General Settings)", EditDefaultsOnly, AdvancedDisplay, meta = (ClampMin = "0.0", ClampMax = "1.0", UIMin = "0.0", UIMax = "1.0"))
  567.         float NetworkSimulatedSmoothLocationTime;
  568.  
  569.     /**
  570.     * How long to take to smoothly interpolate from the old pawn rotation on the client to the corrected one sent by the server.
  571.     */
  572.     UPROPERTY(Category = "Character Movement (General Settings)", EditDefaultsOnly, AdvancedDisplay, meta = (ClampMin = "0.0", ClampMax = "1.0", UIMin = "0.0", UIMax = "1.0"))
  573.         float NetworkSimulatedSmoothRotationTime;
  574.  
  575.     /** Used in determining if pawn is going off ledge.  If the ledge is "shorter" than this value then the pawn will be able to walk off it. **/
  576.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  577.         float LedgeCheckThreshold;
  578.  
  579.     /** When exiting water, jump if control pitch angle is this high or above. */
  580.     UPROPERTY(Category = "Character Movement: Swimming", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  581.         float JumpOutOfWaterPitch;
  582.  
  583.     /** Information about the floor the Character is standing on (updated only during walking movement). */
  584.     UPROPERTY(Category = "Character Movement: Walking", VisibleInstanceOnly, BlueprintReadOnly)
  585.         FFindFloorResult CurrentFloor;
  586.  
  587.     /**
  588.     * Default movement mode when not in water. Used at player startup or when teleported.
  589.     * @see DefaultWaterMovementMode
  590.     * @see bRunPhysicsWithNoController
  591.     */
  592.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite)
  593.         TEnumAsByte<enum EMovementMode> DefaultLandMovementMode;
  594.  
  595.     /**
  596.     * Default movement mode when in water. Used at player startup or when teleported.
  597.     * @see DefaultLandMovementMode
  598.     * @see bRunPhysicsWithNoController
  599.     */
  600.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite)
  601.         TEnumAsByte<enum EMovementMode> DefaultWaterMovementMode;
  602.  
  603. private:
  604.     /**
  605.     * Ground movement mode to switch to after falling and resuming ground movement.
  606.     * Only allowed values are: MOVE_Walking, MOVE_NavWalking.
  607.     * @see SetGroundMovementMode(), GetGroundMovementMode()
  608.     */
  609.     UPROPERTY(Transient)
  610.         TEnumAsByte<enum EMovementMode> GroundMovementMode;
  611.  
  612. public:
  613.     /**
  614.     * If true, walking movement always maintains horizontal velocity when moving up ramps, which causes movement up ramps to be faster parallel to the ramp surface.
  615.     * If false, then walking movement maintains velocity magnitude parallel to the ramp surface.
  616.     */
  617.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite)
  618.         uint32 bMaintainHorizontalGroundVelocity : 1;
  619.  
  620.     /** If true, impart the base actor's X velocity when falling off it (which includes jumping) */
  621.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite)
  622.         uint32 bImpartBaseVelocityX : 1;
  623.  
  624.     /** If true, impart the base actor's Y velocity when falling off it (which includes jumping) */
  625.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite)
  626.         uint32 bImpartBaseVelocityY : 1;
  627.  
  628.     /** If true, impart the base actor's Z velocity when falling off it (which includes jumping) */
  629.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite)
  630.         uint32 bImpartBaseVelocityZ : 1;
  631.  
  632.     /**
  633.     * If true, impart the base component's tangential components of angular velocity when jumping or falling off it.
  634.     * Only those components of the velocity allowed by the separate component settings (bImpartBaseVelocityX etc) will be applied.
  635.     * @see bImpartBaseVelocityX, bImpartBaseVelocityY, bImpartBaseVelocityZ
  636.     */
  637.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite)
  638.         uint32 bImpartBaseAngularVelocity : 1;
  639.  
  640.     /** Used by movement code to determine if a change in position is based on normal movement or a teleport. If not a teleport, velocity can be recomputed based on the change in position. */
  641.     UPROPERTY(Category = "Character Movement (General Settings)", Transient, VisibleInstanceOnly, BlueprintReadWrite)
  642.         uint32 bJustTeleported : 1;
  643.  
  644.     /** True when a network replication update is received for simulated proxies. */
  645.     UPROPERTY(Transient)
  646.         uint32 bNetworkUpdateReceived : 1;
  647.  
  648.     /** True when the networked movement mode has been replicated. */
  649.     UPROPERTY(Transient)
  650.         uint32 bNetworkMovementModeChanged : 1;
  651.  
  652.     /** if true, event NotifyJumpApex() to CharacterOwner's controller when at apex of jump.  Is cleared when event is triggered. */
  653.     UPROPERTY(Category = "Character Movement: Jumping / Falling", EditAnywhere, BlueprintReadWrite)
  654.         uint32 bNotifyApex : 1;
  655.  
  656.     /** Instantly stop when in flying mode and no acceleration is being applied. */
  657.     UPROPERTY()
  658.         uint32 bCheatFlying : 1;
  659.  
  660.     /** If true, try to crouch (or keep crouching) on next update. If false, try to stop crouching on next update. */
  661.     UPROPERTY(Category = "Character Movement (General Settings)", VisibleInstanceOnly, BlueprintReadOnly)
  662.         uint32 bWantsToCrouch : 1;
  663.  
  664.     /**
  665.     * If true, crouching should keep the base of the capsule in place by lowering the center of the shrunken capsule. If false, the base of the capsule moves up and the center stays in place.
  666.     * The same behavior applies when the character uncrouches: if true, the base is kept in the same location and the center moves up. If false, the capsule grows and only moves up if the base impacts something.
  667.     * By default this variable is set when the movement mode changes: set to true when walking and false otherwise. Feel free to override the behavior when the movement mode changes.
  668.     */
  669.     UPROPERTY(Category = "Character Movement (General Settings)", VisibleInstanceOnly, BlueprintReadWrite, AdvancedDisplay)
  670.         uint32 bCrouchMaintainsBaseLocation : 1;
  671.  
  672.     /**
  673.     * Whether the character ignores changes in rotation of the base it is standing on.
  674.     * If true, the character maintains current world rotation.
  675.     * If false, the character rotates with the moving base.
  676.     */
  677.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite)
  678.         uint32 bIgnoreBaseRotation : 1;
  679.  
  680.     /**
  681.     * Set this to true if riding on a moving base that you know is clear from non-moving world obstructions.
  682.     * Optimization to avoid sweeps during based movement, use with care.
  683.     */
  684.     UPROPERTY()
  685.         uint32 bFastAttachedMove : 1;
  686.  
  687.     /**
  688.     * Whether we always force floor checks for stationary Characters while walking.
  689.     * Normally floor checks are avoided if possible when not moving, but this can be used to force them if there are use-cases where they are being skipped erroneously
  690.     * (such as objects moving up into the character from below).
  691.     */
  692.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  693.         uint32 bAlwaysCheckFloor : 1;
  694.  
  695.     /**
  696.     * Performs floor checks as if the character is using a shape with a flat base.
  697.     * This avoids the situation where characters slowly lower off the side of a ledge (as their capsule 'balances' on the edge).
  698.     */
  699.     UPROPERTY(Category = "Character Movement: Walking", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  700.         uint32 bUseFlatBaseForFloorChecks : 1;
  701.  
  702.     /** Used to prevent reentry of JumpOff() */
  703.     UPROPERTY()
  704.         uint32 bPerformingJumpOff : 1;
  705.  
  706.     /** Used to safely leave NavWalking movement mode */
  707.     UPROPERTY()
  708.         uint32 bWantsToLeaveNavWalking : 1;
  709.  
  710.     /** If set, component will use RVO avoidance */
  711.     UPROPERTY(Category = "Character Movement: Avoidance", EditAnywhere, BlueprintReadOnly)
  712.         uint32 bUseRVOAvoidance : 1;
  713.  
  714.     /**
  715.     * Should use acceleration for path following?
  716.     * If true, acceleration is applied when path following to reach the target velocity.
  717.     * If false, path following velocity is set directly, disregarding acceleration.
  718.     */
  719.     UPROPERTY(Category = "Character Movement (General Settings)", EditAnywhere, BlueprintReadWrite, AdvancedDisplay)
  720.         uint32 bRequestedMoveUseAcceleration : 1;
  721.  
  722. protected:
  723.  
  724.     // AI PATH FOLLOWING
  725.  
  726.     /** Was velocity requested by path following? */
  727.     UPROPERTY(Transient)
  728.         uint32 bHasRequestedVelocity : 1;
  729.  
  730.     /** Was acceleration requested to be always max speed? */
  731.     UPROPERTY(Transient)
  732.         uint32 bRequestedMoveWithMaxSpeed : 1;
  733.  
  734.     /** Was avoidance updated in this frame? */
  735.     UPROPERTY(Transient)
  736.         uint32 bWasAvoidanceUpdated : 1;
  737.  
  738.     /** if set, PostProcessAvoidanceVelocity will be called */
  739.     uint32 bUseRVOPostProcess : 1;
  740.  
  741.     /** Flag set in pre-physics update to indicate that based movement should be updated post-physics */
  742.     uint32 bDeferUpdateBasedMovement : 1;
  743.  
  744.     /** Whether to raycast to underlying geometry to better conform navmesh-walking characters */
  745.     UPROPERTY(Category = "Character Movement: NavMesh Movement", EditAnywhere, BlueprintReadOnly)
  746.         uint32 bProjectNavMeshWalking : 1;
  747.  
  748.     /** forced avoidance velocity, used when AvoidanceLockTimer is > 0 */
  749.     FVector AvoidanceLockVelocity;
  750.  
  751.     /** remaining time of avoidance velocity lock */
  752.     float AvoidanceLockTimer;
  753.  
  754. public:
  755.  
  756.     UPROPERTY(Category = "Character Movement: Avoidance", EditAnywhere, BlueprintReadOnly)
  757.         float AvoidanceConsiderationRadius;
  758.  
  759.     /**
  760.     * Velocity requested by path following.
  761.     * @see RequestDirectMove()
  762.     */
  763.     UPROPERTY(Transient)
  764.         FVector RequestedVelocity;
  765.  
  766.     /** No default value, for now it's assumed to be valid if GetAvoidanceManager() returns non-NULL. */
  767.     UPROPERTY(Category = "Character Movement: Avoidance", VisibleAnywhere, BlueprintReadOnly, AdvancedDisplay)
  768.         int32 AvoidanceUID;
  769.  
  770.     /** Moving actor's group mask */
  771.     UPROPERTY(Category = "Character Movement: Avoidance", EditAnywhere, BlueprintReadOnly, AdvancedDisplay)
  772.         FNavAvoidanceMask AvoidanceGroup;
  773.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  774.         void SetAvoidanceGroup(int32 GroupFlags);
  775.  
  776.     /** Will avoid other agents if they are in one of specified groups */
  777.     UPROPERTY(Category = "Character Movement: Avoidance", EditAnywhere, BlueprintReadOnly, AdvancedDisplay)
  778.         FNavAvoidanceMask GroupsToAvoid;
  779.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  780.         void SetGroupsToAvoid(int32 GroupFlags);
  781.  
  782.     /** Will NOT avoid other agents if they are in one of specified groups, higher priority than GroupsToAvoid */
  783.     UPROPERTY(Category = "Character Movement: Avoidance", EditAnywhere, BlueprintReadOnly, AdvancedDisplay)
  784.         FNavAvoidanceMask GroupsToIgnore;
  785.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  786.         void SetGroupsToIgnore(int32 GroupFlags);
  787.  
  788.     /** De facto default value 0.5 (due to that being the default in the avoidance registration function), indicates RVO behavior. */
  789.     UPROPERTY(Category = "Character Movement: Avoidance", EditAnywhere, BlueprintReadOnly)
  790.         float AvoidanceWeight;
  791.  
  792.     /** Temporarily holds launch velocity when pawn is to be launched so it happens at end of movement. */
  793.     UPROPERTY()
  794.         FVector PendingLaunchVelocity;
  795.  
  796.     /** last known location projected on navmesh, used by NavWalking mode */
  797.     FNavLocation CachedNavLocation;
  798.  
  799.     /** Last valid projected hit result from raycast to geometry from navmesh */
  800.     FHitResult CachedProjectedNavMeshHitResult;
  801.  
  802.     /** How often we should raycast to project from navmesh to underlying geometry */
  803.     UPROPERTY(Category = "Character Movement: NavMesh Movement", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bProjectNavMeshWalking"))
  804.         float NavMeshProjectionInterval;
  805.  
  806.     UPROPERTY(Transient)
  807.         float NavMeshProjectionTimer;
  808.  
  809.     /** Speed at which to interpolate agent navmesh offset between traces. 0: Instant (no interp) > 0: Interp speed") */
  810.     UPROPERTY(Category = "Character Movement: NavMesh Movement", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bProjectNavMeshWalking", ClampMin = "0", UIMin = "0"))
  811.         float NavMeshProjectionInterpSpeed;
  812.  
  813.     /**
  814.     * Scale of the total capsule height to use for projection from navmesh to underlying geometry in the upward direction.
  815.     * In other words, start the trace at [CapsuleHeight * NavMeshProjectionHeightScaleUp] above nav mesh.
  816.     */
  817.     UPROPERTY(Category = "Character Movement: NavMesh Movement", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bProjectNavMeshWalking", ClampMin = "0", UIMin = "0"))
  818.         float NavMeshProjectionHeightScaleUp;
  819.  
  820.     /**
  821.     * Scale of the total capsule height to use for projection from navmesh to underlying geometry in the downward direction.
  822.     * In other words, trace down to [CapsuleHeight * NavMeshProjectionHeightScaleDown] below nav mesh.
  823.     */
  824.     UPROPERTY(Category = "Character Movement: NavMesh Movement", EditAnywhere, BlueprintReadWrite, meta = (editcondition = "bProjectNavMeshWalking", ClampMin = "0", UIMin = "0"))
  825.         float NavMeshProjectionHeightScaleDown;
  826.  
  827.     /** Change avoidance state and registers in RVO manager if needed */
  828.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement", meta = (UnsafeDuringActorConstruction = "true"))
  829.         void SetAvoidanceEnabled(bool bEnable);
  830.  
  831.     /** Get the Character that owns UpdatedComponent. */
  832.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  833.         ACharacter* GetCharacterOwner() const;
  834.  
  835.     /**
  836.     * Change movement mode.
  837.     *
  838.     * @param NewMovementMode    The new movement mode
  839.     * @param NewCustomMode      The new custom sub-mode, only applicable if NewMovementMode is Custom.
  840.     */
  841.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  842.         virtual void SetMovementMode(EMovementMode NewMovementMode, uint8 NewCustomMode = 0);
  843.  
  844.     /**
  845.     * Set movement mode to use when returning to walking movement (either MOVE_Walking or MOVE_NavWalking).
  846.     * If movement mode is currently one of Walking or NavWalking, this will also change the current movement mode (via SetMovementMode())
  847.     * if the new mode is not the current ground mode.
  848.     *
  849.     * @param  NewGroundMovementMode New ground movement mode. Must be either MOVE_Walking or MOVE_NavWalking, other values are ignored.
  850.     * @see GroundMovementMode
  851.     */
  852.     void SetGroundMovementMode(EMovementMode NewGroundMovementMode);
  853.  
  854.     /**
  855.     * Get current GroundMovementMode value.
  856.     * @return current GroundMovementMode
  857.     * @see GroundMovementMode, SetGroundMovementMode()
  858.     */
  859.     EMovementMode GetGroundMovementMode() const { return GroundMovementMode; }
  860.  
  861. protected:
  862.  
  863.     /** Called after MovementMode has changed. Base implementation does special handling for starting certain modes, then notifies the CharacterOwner. */
  864.     virtual void OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode);
  865.  
  866. public:
  867.  
  868.     uint8 PackNetworkMovementMode() const;
  869.     void UnpackNetworkMovementMode(const uint8 ReceivedMode, TEnumAsByte<EMovementMode>& OutMode, uint8& OutCustomMode, TEnumAsByte<EMovementMode>& OutGroundMode) const;
  870.     virtual void ApplyNetworkMovementMode(const uint8 ReceivedMode);
  871.  
  872.     //Begin UActorComponent Interface
  873.     virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
  874.     virtual void OnRegister() override;
  875.     virtual void BeginDestroy() override;
  876.     virtual void PostLoad() override;
  877.     virtual void RegisterComponentTickFunctions(bool bRegister) override;
  878.     //End UActorComponent Interface
  879.  
  880.     //BEGIN UMovementComponent Interface
  881.     virtual float GetMaxSpeed() const override;
  882.     virtual void StopActiveMovement() override;
  883.     virtual bool IsCrouching() const override;
  884.     virtual bool IsFalling() const override;
  885.     virtual bool IsMovingOnGround() const override;
  886.     virtual bool IsSwimming() const override;
  887.     virtual bool IsFlying() const override;
  888.     virtual float GetGravityZ() const override;
  889.     virtual void AddRadialForce(const FVector& Origin, float Radius, float Strength, enum ERadialImpulseFalloff Falloff) override;
  890.     virtual void AddRadialImpulse(const FVector& Origin, float Radius, float Strength, enum ERadialImpulseFalloff Falloff, bool bVelChange) override;
  891.     //END UMovementComponent Interface
  892.  
  893.     /** @return true if the character is in the 'Walking' movement mode. */
  894.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  895.         bool IsWalking() const;
  896.  
  897.     /**
  898.     * @return true if currently performing a movement update.
  899.     * @see bMovementInProgress
  900.     */
  901.     bool IsMovementInProgress() const { return bMovementInProgress; }
  902.  
  903.     //BEGIN UNavMovementComponent Interface
  904.     virtual void RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed) override;
  905.     virtual bool CanStartPathFollowing() const override;
  906.     virtual bool CanStopPathFollowing() const override;
  907.     //END UNaVMovementComponent Interface
  908.  
  909.     //Begin UPawnMovementComponent Interface
  910.     virtual void NotifyBumpedPawn(APawn* BumpedPawn) override;
  911.     //End UPawnMovementComponent Interface
  912.  
  913. #if WITH_EDITOR
  914.     virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
  915. #endif // WITH_EDITOR
  916.  
  917.     /** Make movement impossible (sets movement mode to MOVE_None). */
  918.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  919.         virtual void DisableMovement();
  920.  
  921.     /** Return true if we have a valid CharacterOwner and UpdatedComponent. */
  922.     virtual bool HasValidData() const;
  923.  
  924.     /**
  925.     * Update Velocity and Acceleration to air control in the desired Direction for character using path following.
  926.     * @param Direction is the desired direction of movement
  927.     * @param ZDiff is the height difference between the destination and the Pawn's current position
  928.     * @see RequestDirectMove()
  929.     */
  930.     virtual void PerformAirControlForPathFollowing(const FVector& Direction, float ZDiff);
  931.  
  932.     DEPRECATED(4.5, "PerformAirControl has been deprecated, use PerformAirControlForPathFollowing instead.")
  933.         virtual void PerformAirControl(FVector Direction, float ZDiff);
  934.  
  935.     /**
  936.     * If true, the vertical component of velocity is set to zero when transitioning from walking to falling.
  937.     */
  938.     UPROPERTY(Category = "Character Movement", BlueprintReadWrite, EditAnywhere)
  939.         uint32 bFallingRemovesSpeedZ : 1;
  940.  
  941.     /** Transition from walking to falling */
  942.     virtual void StartFalling(int32 Iterations, float remainingTime, float timeTick, const FVector& Delta, const FVector& subLoc);
  943.  
  944.     /**
  945.     * Whether Character should go into falling mode when walking and changing position, based on an old and new floor result (both of which are considered walkable).
  946.     * Default implementation always returns false.
  947.     * @return true if Character should start falling
  948.     */
  949.     virtual bool ShouldCatchAir(const FFindFloorResult& OldFloor, const FFindFloorResult& NewFloor);
  950.  
  951.     /** Adjust distance from floor, trying to maintain a slight offset from the floor when walking (based on CurrentFloor). */
  952.     virtual void AdjustFloorHeight();
  953.  
  954.     /** Return PrimitiveComponent we are based on (standing and walking on). */
  955.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  956.         UPrimitiveComponent* GetMovementBase() const;
  957.  
  958.     /** Update or defer updating of position based on Base movement */
  959.     virtual void MaybeUpdateBasedMovement(float DeltaSeconds);
  960.  
  961.     /** Update position based on Base movement */
  962.     virtual void UpdateBasedMovement(float DeltaSeconds);
  963.  
  964.     /**
  965.     * If true and the pawn's base moved, the roll components of pawn rotation and control rotation are tampered with.
  966.     */
  967.     UPROPERTY(Category = "Character Movement", BlueprintReadWrite, EditAnywhere)
  968.         uint32 bIgnoreBaseRollMove : 1;
  969.  
  970.     /** Update controller's view rotation as pawn's base rotates */
  971.     virtual void UpdateBasedRotation(FRotator& FinalRotation, const FRotator& ReducedRotation);
  972.  
  973.     /** Update (or defer updating) OldBaseLocation and OldBaseQuat if there is a valid movement base. */
  974.     DEPRECATED(4.4, "CharacterMovementComponent::MaybeSaveBaseLocation() will be removed, call SaveBaseLocation().")
  975.         virtual void MaybeSaveBaseLocation();
  976.  
  977.     /** Update OldBaseLocation and OldBaseQuat if there is a valid movement base, and store the relative location/rotation if necessary. */
  978.     virtual void SaveBaseLocation();
  979.  
  980.     /** changes physics based on MovementMode */
  981.     virtual void StartNewPhysics(float deltaTime, int32 Iterations);
  982.  
  983.     /**
  984.     * Perform jump. Called by Character when a jump has been detected because Character->bPressedJump was true. Checks CanJump().
  985.     * Note that you should usually trigger a jump through Character::Jump() instead.
  986.     * @param    bReplayingMoves: true if this is being done as part of replaying moves on a locally controlled client after a server correction.
  987.     * @return   True if the jump was triggered successfully.
  988.     */
  989.     virtual bool DoJump(bool bReplayingMoves);
  990.  
  991.     /** Queue a pending launch with velocity LaunchVel. */
  992.     virtual void Launch(FVector const& LaunchVel);
  993.  
  994.     /** Handle a pending launch during an update. Returns true if the launch was triggered. */
  995.     virtual bool HandlePendingLaunch();
  996.  
  997.     /**
  998.     * If we have a movement base, get the velocity that should be imparted by that base, usually when jumping off of it.
  999.     * Only applies the components of the velocity enabled by bImpartBaseVelocityX, bImpartBaseVelocityY, bImpartBaseVelocityZ.
  1000.     */
  1001.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1002.         virtual FVector GetImpartedMovementBaseVelocity() const;
  1003.  
  1004.     /** Force this pawn to bounce off its current base, which isn't an acceptable base for it. */
  1005.     virtual void JumpOff(AActor* MovementBaseActor);
  1006.  
  1007.     /** Can be overridden to choose to jump based on character velocity, base actor dimensions, etc. */
  1008.     virtual FVector GetBestDirectionOffActor(AActor* BaseActor) const; // Calculates the best direction to go to "jump off" an actor.
  1009.  
  1010.     /**
  1011.     * Determine whether the Character should jump when exiting water.
  1012.     * @param    JumpDir is the desired direction to jump out of water
  1013.     * @param    GravDir is the normalized direction of gravity
  1014.     * @return   true if Pawn should jump out of water
  1015.     */
  1016.     virtual bool ShouldJumpOutOfWater(FVector& JumpDir, const FVector& GravDir);
  1017.  
  1018.     /** Jump onto shore from water */
  1019.     virtual void JumpOutOfWater(const FVector& WallNormal);
  1020.  
  1021.     /** @return how far to rotate character during the time interval DeltaTime. */
  1022.     virtual FRotator GetDeltaRotation(float DeltaTime) const;
  1023.  
  1024.     /**
  1025.     * Compute a target rotation based on current movement. Used by PhysicsRotation() when bOrientRotationToMovement is true.
  1026.     * Default implementation targets a rotation based on Acceleration.
  1027.     *
  1028.     * @param CurrentRotation    - Current rotation of the Character
  1029.     * @param DeltaTime      - Time slice for this movement
  1030.     * @param DeltaRotation  - Proposed rotation change based simply on DeltaTime * RotationRate
  1031.     *
  1032.     * @return The target rotation given current movement.
  1033.     */
  1034.     virtual FRotator ComputeOrientToMovementRotation(const FRotator& CurrentRotation, float DeltaTime, FRotator& DeltaRotation) const;
  1035.  
  1036.     /**
  1037.     * Use velocity requested by path following to compute a requested acceleration and speed.
  1038.     * This does not affect the Acceleration member variable, as that is used to indicate input acceleration.
  1039.     * This may directly affect current Velocity.
  1040.     *
  1041.     * @param DeltaTime              Time slice for this operation
  1042.     * @param MaxAccel               Max acceleration allowed in OutAcceleration result.
  1043.     * @param MaxSpeed               Max speed allowed when computing OutRequestedSpeed.
  1044.     * @param Friction               Current friction.
  1045.     * @param BrakingDeceleration    Current braking deceleration.
  1046.     * @param OutAcceleration        Acceleration computed based on requested velocity.
  1047.     * @param OutRequestedSpeed      Speed of resulting velocity request, which can affect the max speed allowed by movement.
  1048.     * @return Whether there is a requested velocity and acceleration, resulting in valid OutAcceleration and OutRequestedSpeed values.
  1049.     */
  1050.     virtual bool ApplyRequestedMove(float DeltaTime, float MaxAccel, float MaxSpeed, float Friction, float BrakingDeceleration, FVector& OutAcceleration, float& OutRequestedSpeed);
  1051.  
  1052.     /** Called if bNotifyApex is true and character has just passed the apex of its jump. */
  1053.     virtual void NotifyJumpApex();
  1054.  
  1055.     /**
  1056.     * Compute new falling velocity from given velocity and gravity. Applies the limits of the current Physics Volume's TerminalVelocity.
  1057.     */
  1058.     virtual FVector NewFallVelocity(const FVector& InitialVelocity, const FVector& Gravity, float DeltaTime) const;
  1059.  
  1060.     /**
  1061.     * Determine how deep in water the character is immersed.
  1062.     * @return float in range 0.0 = not in water, 1.0 = fully immersed
  1063.     */
  1064.     virtual float ImmersionDepth() const;
  1065.  
  1066.     /**
  1067.     * Updates Velocity and Acceleration based on the current state, applying the effects of friction and acceleration or deceleration. Does not apply gravity.
  1068.     * This is used internally during movement updates. Normally you don't need to call this from outside code, but you might want to use it for custom movement modes.
  1069.     *
  1070.     * @param    DeltaTime                       time elapsed since last frame.
  1071.     * @param    Friction                        coefficient of friction when not accelerating, or in the direction opposite acceleration.
  1072.     * @param    bFluid                          true if moving through a fluid, causing Friction to always be applied regardless of acceleration.
  1073.     * @param    BrakingDeceleration             deceleration applied when not accelerating, or when exceeding max velocity.
  1074.     */
  1075.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1076.         virtual void CalcVelocity(float DeltaTime, float Friction, bool bFluid, float BrakingDeceleration);
  1077.  
  1078.     /** Compute the max jump height based on the JumpZVelocity velocity and gravity. */
  1079.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1080.         virtual float GetMaxJumpHeight() const;
  1081.  
  1082.     /** @return Maximum acceleration for the current state, based on MaxAcceleration and any additional modifiers. */
  1083.     DEPRECATED(4.3, "GetModifiedMaxAcceleration() is deprecated, apply your own modifiers to GetMaxAcceleration() if desired.")
  1084.         virtual float GetModifiedMaxAcceleration() const;
  1085.  
  1086.     /** @return Maximum acceleration for the current state, based on MaxAcceleration and any additional modifiers. */
  1087.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement", meta = (DeprecatedFunction, FriendlyName = "GetModifiedMaxAcceleration", DeprecationMessage = "GetModifiedMaxAcceleration() is deprecated, apply your own modifiers to GetMaxAcceleration() if desired."))
  1088.         virtual float K2_GetModifiedMaxAcceleration() const;
  1089.  
  1090.     /** @return Maximum acceleration for the current state. */
  1091.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1092.         virtual float GetMaxAcceleration() const;
  1093.  
  1094.     /** @return Current acceleration, computed from input vector each update. */
  1095.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement", meta = (Keywords = "Acceleration GetAcceleration"))
  1096.         FVector GetCurrentAcceleration() const;
  1097.  
  1098.     /** @return Modifier [0..1] based on the magnitude of the last input vector, which is used to modify the acceleration and max speed during movement. */
  1099.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1100.         float GetAnalogInputModifier() const;
  1101.  
  1102.     /** @return true if we can step up on the actor in the given FHitResult. */
  1103.     virtual bool CanStepUp(const FHitResult& Hit) const;
  1104.  
  1105.     /** Struct updated by StepUp() to return result of final step down, if applicable. */
  1106.     struct FStepDownResult
  1107.     {
  1108.         uint32 bComputedFloor : 1;      // True if the floor was computed as a result of the step down.
  1109.         FFindFloorResult FloorResult;   // The result of the floor test if the floor was updated.
  1110.  
  1111.         FStepDownResult()
  1112.             : bComputedFloor(false)
  1113.         {
  1114.         }
  1115.     };
  1116.  
  1117.     /**
  1118.     * Move up steps or slope. Does nothing and returns false if CanStepUp(Hit) returns false.
  1119.     *
  1120.     * @param GravDir            Gravity vector
  1121.     * @param Delta              Requested move
  1122.     * @param Hit                [In] The hit before the step up.
  1123.     * @param OutStepDownResult  [Out] If non-null, a floor check will be performed if possible as part of the final step down, and it will be updated to reflect this result.
  1124.     * @return true if the step up was successful.
  1125.     */
  1126.     virtual bool StepUp(const FVector& GravDir, const FVector& Delta, const FHitResult &Hit, struct UCharacterMovementComponent::FStepDownResult* OutStepDownResult = NULL);
  1127.  
  1128.     /** Update the base of the character, which is the PrimitiveComponent we are standing on. */
  1129.     virtual void SetBase(UPrimitiveComponent* NewBase, const FName BoneName = NAME_None, bool bNotifyActor = true);
  1130.  
  1131.     /**
  1132.     * Update the base of the character, using the given floor result if it is walkable, or null if not. Calls SetBase().
  1133.     */
  1134.     void SetBaseFromFloor(const FFindFloorResult& FloorResult);
  1135.  
  1136.     /**
  1137.     * Applies downward force when walking on top of physics objects.
  1138.     *
  1139.     * @param DeltaSeconds - Time elapsed since last frame.
  1140.     */
  1141.     virtual void ApplyDownwardForce(float DeltaSeconds);
  1142.  
  1143.     /** Applies repulsion force to all touched components. */
  1144.     virtual void ApplyRepulsionForce(float DeltaSeconds);
  1145.  
  1146.     /** Applies momentum accumulated through AddImpulse() and AddForce(). */
  1147.     virtual void ApplyAccumulatedForces(float DeltaSeconds);
  1148.  
  1149.     /**
  1150.     * Handle start swimming functionality
  1151.     * @param OldLocation - Location on last tick
  1152.     * @param OldVelocity - velocity at last tick
  1153.     * @param timeTick - time since at OldLocation
  1154.     * @param remainingTime - DeltaTime to complete transition to swimming
  1155.     * @param Iterations - physics iteration count
  1156.     */
  1157.     virtual void StartSwimming(const FVector& OldLocation, const FVector& OldVelocity, float timeTick, float remainingTime, int32 Iterations);
  1158.  
  1159.     /* Swimming uses gravity - but scaled by (1.f - buoyancy) */
  1160.     float Swim(const FVector& Delta, FHitResult& Hit);
  1161.  
  1162.     /** Get as close to waterline as possible, staying on same side as currently. */
  1163.     FVector FindWaterLine(const FVector& Start, const FVector& End) const;
  1164.  
  1165.     /** Handle falling movement. */
  1166.     virtual void PhysFalling(float deltaTime, int32 Iterations);
  1167.  
  1168.     // Helpers for PhysFalling
  1169.  
  1170.     /**
  1171.     * Get the lateral acceleration to use during falling movement. The Z component of the result is ignored.
  1172.     * Default implementation returns current Acceleration value modified by GetAirControl(), with Z component removed,
  1173.     * with magnitude clamped to GetMaxAcceleration().
  1174.     * This function is used internally by PhysFalling().
  1175.     *
  1176.     * @param DeltaTime Time step for the current update.
  1177.     * @param GravDir Normalized direction of gravity.
  1178.     * @return Acceleration to use during falling movement.
  1179.     */
  1180.     virtual FVector GetFallingLateralAcceleration(float DeltaTime, const FVector& GravDir) const;
  1181.  
  1182.     /**
  1183.     * Get the air control to use during falling movement.
  1184.     * Given an initial air control (TickAirControl), applies the result of BoostAirControl().
  1185.     * This function is used internally by GetFallingLateralAcceleration().
  1186.     *
  1187.     * @param DeltaTime          Time step for the current update.
  1188.     * @param TickAirControl Current air control value.
  1189.     * @param FallAcceleration   Acceleration used during movement.
  1190.     * @return Air control to use during falling movement.
  1191.     * @see AirControl, BoostAirControl(), LimitAirControl(), GetFallingLateralAcceleration()
  1192.     */
  1193.     virtual FVector GetAirControl(float DeltaTime, float TickAirControl, const FVector& FallAcceleration) const;
  1194.  
  1195. protected:
  1196.  
  1197.     /**
  1198.     * Increase air control if conditions of AirControlBoostMultiplier and AirControlBoostVelocityThreshold are met.
  1199.     * This function is used internally by GetAirControl().
  1200.     *
  1201.     * @param DeltaTime          Time step for the current update.
  1202.     * @param TickAirControl Current air control value.
  1203.     * @param FallAcceleration   Acceleration used during movement.
  1204.     * @return Modified air control to use during falling movement
  1205.     * @see GetAirControl()
  1206.     */
  1207.     virtual float BoostAirControl(float DeltaTime, float TickAirControl, const FVector& FallAcceleration) const;
  1208.  
  1209.     /**
  1210.     * (DEPRECATED) Checks if air control will cause the player collision shape to hit something given the current location.
  1211.     *
  1212.     * @param DeltaTime          Time step for the current update.
  1213.     * @param AdditionalTime Time to look ahead further, applying acceleration and gravity.
  1214.     * @param FallVelocity       Velocity to test with.
  1215.     * @param FallAcceleration   Acceleration used during movement.
  1216.     * @param Gravity            Gravity to apply to any additional time.
  1217.     * @param OutHitResult       Result of impact, valid if this function returns true.
  1218.     * @return True if there is an impact, in which case OutHitResult contains the result of that impact.
  1219.     * @see GetAirControl()
  1220.     */
  1221.     DEPRECATED(4.9, "FindAirControlImpact is no longer used by engine code.")
  1222.         virtual bool FindAirControlImpact(float DeltaTime, float AdditionalTime, const FVector& FallVelocity, const FVector& FallAcceleration, const FVector& Gravity, FHitResult& OutHitResult) const;
  1223.  
  1224.     /**
  1225.     * Limits the air control to use during falling movement, given an impact from FindAirControlImpact().
  1226.     * This function is used internally by PhysFalling().
  1227.     *
  1228.     * @param DeltaTime          Time step for the current update.
  1229.     * @param FallAcceleration   Acceleration used during movement.
  1230.     * @param HitResult          Result of impact.
  1231.     * @param GravDir            Normalized direction of gravity.
  1232.     * @param bCheckForValidLandingSpot If true, will use IsValidLandingSpot() to determine if HitResult is a walkable surface. If false, this check is skipped.
  1233.     * @return Modified air control acceleration to use during falling movement.
  1234.     * @see FindAirControlImpact()
  1235.     */
  1236.     virtual FVector LimitAirControl(float DeltaTime, const FVector& FallAcceleration, const FHitResult& HitResult, const FVector& GravDir, bool bCheckForValidLandingSpot) const;
  1237.  
  1238.  
  1239.     /** Handle landing against Hit surface over remaingTime and iterations, calling SetPostLandedPhysics() and starting the new movement mode. */
  1240.     virtual void ProcessLanded(const FHitResult& Hit, float remainingTime, int32 Iterations);
  1241.  
  1242.     /** Use new physics after landing. Defaults to swimming if in water, walking otherwise. */
  1243.     virtual void SetPostLandedPhysics(const FHitResult& Hit);
  1244.  
  1245.     /** Switch collision settings for NavWalking mode (ignore world collisions) */
  1246.     virtual void SetNavWalkingPhysics(bool bEnable);
  1247.  
  1248.     /** Get Navigation data for the Character. Returns null if there is no associated nav data. */
  1249.     const class ANavigationData* GetNavData() const;
  1250.  
  1251.     /**
  1252.     * Checks to see if the current location is not encroaching blocking geometry so the character can leave NavWalking.
  1253.     * Restores collision settings and adjusts character location to avoid getting stuck in geometry.
  1254.     * If it's not possible, MovementMode change will be delayed until character reach collision free spot.
  1255.     * @return True if movement mode was successfully changed
  1256.     */
  1257.     virtual bool TryToLeaveNavWalking();
  1258.  
  1259.     /**
  1260.     * Attempts to better align navmesh walking characters with underlying geometry (sometimes
  1261.     * navmesh can differ quite significantly from geometry).
  1262.     * Updates CachedProjectedNavMeshHitResult, access this for more info about hits.
  1263.     */
  1264.     virtual FVector ProjectLocationFromNavMesh(float DeltaSeconds, const FVector& CurrentFeetLocation, const FVector& TargetNavLocation, float UpOffset, float DownOffset);
  1265.  
  1266. public:
  1267.  
  1268.     /** Called by owning Character upon successful teleport from AActor::TeleportTo(). */
  1269.     virtual void OnTeleported() override;
  1270.  
  1271.     /**
  1272.     * Checks if new capsule size fits (no encroachment), and call CharacterOwner->OnStartCrouch() if successful.
  1273.     * In general you should set bWantsToCrouch instead to have the crouch persist during movement, or just use the crouch functions on the owning Character.
  1274.     * @param    bClientSimulation   true when called when bIsCrouched is replicated to non owned clients, to update collision cylinder and offset.
  1275.     */
  1276.     virtual void Crouch(bool bClientSimulation = false);
  1277.  
  1278.     /**
  1279.     * Checks if default capsule size fits (no encroachment), and trigger OnEndCrouch() on the owner if successful.
  1280.     * @param    bClientSimulation   true when called when bIsCrouched is replicated to non owned clients, to update collision cylinder and offset.
  1281.     */
  1282.     virtual void UnCrouch(bool bClientSimulation = false);
  1283.  
  1284.     /** @return true if the character is allowed to crouch in the current state. By default it is allowed when walking or falling, if CanEverCrouch() is true. */
  1285.     virtual bool CanCrouchInCurrentState() const;
  1286.  
  1287.     /** @return true if there is a suitable floor SideStep from current position. */
  1288.     virtual bool CheckLedgeDirection(const FVector& OldLocation, const FVector& SideStep, const FVector& GravDir) const;
  1289.  
  1290.     /**
  1291.     * @param Delta is the current move delta (which ended up going over a ledge).
  1292.     * @return new delta which moves along the ledge
  1293.     */
  1294.     virtual FVector GetLedgeMove(const FVector& OldLocation, const FVector& Delta, const FVector& GravDir) const;
  1295.  
  1296.     /** Check if pawn is falling */
  1297.     virtual bool CheckFall(const FFindFloorResult& OldFloor, const FHitResult& Hit, const FVector& Delta, const FVector& subLoc, float remainingTime, float timeTick, int32 Iterations, bool bMustJump);
  1298.  
  1299.     /**
  1300.     *  Revert to previous position OldLocation, return to being based on OldBase.
  1301.     *  if bFailMove, stop movement and notify controller
  1302.     */
  1303.     void RevertMove(const FVector& OldLocation, UPrimitiveComponent* OldBase, const FVector& OldBaseLocation, const FFindFloorResult& OldFloor, bool bFailMove);
  1304.  
  1305.     /** Perform rotation over deltaTime */
  1306.     virtual void PhysicsRotation(float DeltaTime);
  1307.  
  1308.     /** Delegate when PhysicsVolume of UpdatedComponent has been changed **/
  1309.     virtual void PhysicsVolumeChanged(class APhysicsVolume* NewVolume) override;
  1310.  
  1311.     /** Set movement mode to the default based on the current physics volume. */
  1312.     virtual void SetDefaultMovementMode();
  1313.  
  1314.     /**
  1315.     * Moves along the given movement direction using simple movement rules based on the current movement mode (usually used by simulated proxies).
  1316.     *
  1317.     * @param InVelocity:            Velocity of movement
  1318.     * @param DeltaSeconds:          Time over which movement occurs
  1319.     * @param OutStepDownResult: [Out] If non-null, and a floor check is performed, this will be updated to reflect that result.
  1320.     */
  1321.     virtual void MoveSmooth(const FVector& InVelocity, const float DeltaSeconds, FStepDownResult* OutStepDownResult = NULL);
  1322.  
  1323.  
  1324.     virtual void SetUpdatedComponent(USceneComponent* NewUpdatedComponent) override;
  1325.  
  1326.     /** @Return MovementMode string */
  1327.     virtual FString GetMovementName() const;
  1328.  
  1329.     /**
  1330.     * Add impulse to character. Impulses are accumulated each tick and applied together
  1331.     * so multiple calls to this function will accumulate.
  1332.     * An impulse is an instantaneous force, usually applied once. If you want to continually apply
  1333.     * forces each frame, use AddForce().
  1334.     * Note that changing the momentum of characters like this can change the movement mode.
  1335.     *
  1336.     * @param    Impulse             Impulse to apply.
  1337.     * @param    bVelocityChange     Whether or not the impulse is relative to mass.
  1338.     */
  1339.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1340.         virtual void AddImpulse(FVector Impulse, bool bVelocityChange = false);
  1341.  
  1342.     /**
  1343.     * Add force to character. Forces are accumulated each tick and applied together
  1344.     * so multiple calls to this function will accumulate.
  1345.     * Forces are scaled depending on timestep, so they can be applied each frame. If you want an
  1346.     * instantaneous force, use AddImpulse.
  1347.     * Adding a force always takes the actor's mass into account.
  1348.     * Note that changing the momentum of characters like this can change the movement mode.
  1349.     *
  1350.     * @param    Force           Force to apply.
  1351.     */
  1352.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1353.         virtual void AddForce(FVector Force);
  1354.  
  1355.     /**
  1356.     * Draw important variables on canvas.  Character will call DisplayDebug() on the current ViewTarget when the ShowDebug exec is used
  1357.     *
  1358.     * @param Canvas - Canvas to draw on
  1359.     * @param DebugDisplay - Contains information about what debug data to display
  1360.     * @param YL - Height of the current font
  1361.     * @param YPos - Y position on Canvas. YPos += YL, gives position to draw text for next debug line.
  1362.     */
  1363.     virtual void DisplayDebug(class UCanvas* Canvas, const FDebugDisplayInfo& DebugDisplay, float& YL, float& YPos);
  1364.  
  1365.     /**
  1366.     * Draw in-world debug information for character movement (called with p.VisualizeMovement > 0).
  1367.     */
  1368.     virtual void VisualizeMovement() const;
  1369.  
  1370.     /** Check if swimming pawn just ran into edge of the pool and should jump out. */
  1371.     virtual bool CheckWaterJump(const FVector& JumpDir, const FVector& GravDir, FVector& WallNormal) const;
  1372.  
  1373.     /** @return whether this pawn is currently allowed to walk off ledges */
  1374.     virtual bool CanWalkOffLedges() const;
  1375.  
  1376.     /** @return The distance from the edge of the capsule within which we don't allow the character to perch on the edge of a surface. */
  1377.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1378.         float GetPerchRadiusThreshold() const;
  1379.  
  1380.     /**
  1381.     * Returns the radius within which we can stand on the edge of a surface without falling (if this is a walkable surface).
  1382.     * Simply computed as the capsule radius minus the result of GetPerchRadiusThreshold().
  1383.     */
  1384.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1385.         float GetValidPerchRadius() const;
  1386.  
  1387.     /** Return true if the hit result should be considered a walkable surface for the character. */
  1388.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1389.         virtual bool IsWalkable(const FHitResult& Hit) const;
  1390.  
  1391.     /** Get the max angle in degrees of a walkable surface for the character. */
  1392.     FORCEINLINE float GetWalkableFloorAngle() const { return WalkableFloorAngle; }
  1393.  
  1394.     /** Get the max angle in degrees of a walkable surface for the character. */
  1395.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement", meta = (FriendlyName = "GetWalkableFloorAngle"))
  1396.         float K2_GetWalkableFloorAngle() const;
  1397.  
  1398.     /** Set the max angle in degrees of a walkable surface for the character. Also computes WalkableFloorZ. */
  1399.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1400.         void SetWalkableFloorAngle(float InWalkableFloorAngle);
  1401.  
  1402.     /** Get the Z component of the normal of the steepest walkable surface for the character. Any lower than this and it is not walkable. */
  1403.     FORCEINLINE float GetWalkableFloorZ() const { return WalkableFloorZ; }
  1404.  
  1405.     /** Get the Z component of the normal of the steepest walkable surface for the character. Any lower than this and it is not walkable. */
  1406.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement", meta = (FriendlyName = "GetWalkableFloorZ"))
  1407.         float K2_GetWalkableFloorZ() const;
  1408.  
  1409.     /** Set the Z component of the normal of the steepest walkable surface for the character. Also computes WalkableFloorAngle. */
  1410.     UFUNCTION(BlueprintCallable, Category = "Pawn|Components|CharacterMovement")
  1411.         void SetWalkableFloorZ(float InWalkableFloorZ);
  1412.  
  1413.     /** Post-physics tick function for this character */
  1414.     UPROPERTY()
  1415.     struct FCharacterMovementComponentPreClothTickFunction PreClothComponentTick;
  1416.  
  1417.     /** Tick function called after physics (sync scene) has finished simulation, before cloth */
  1418.     virtual void PreClothTick(float DeltaTime, FCharacterMovementComponentPreClothTickFunction& ThisTickFunction);
  1419.  
  1420. protected:
  1421.     /** @note Movement update functions should only be called through StartNewPhysics()*/
  1422.     virtual void PhysWalking(float deltaTime, int32 Iterations);
  1423.  
  1424.     /** @note Movement update functions should only be called through StartNewPhysics()*/
  1425.     virtual void PhysNavWalking(float deltaTime, int32 Iterations);
  1426.  
  1427.     /** @note Movement update functions should only be called through StartNewPhysics()*/
  1428.     virtual void PhysFlying(float deltaTime, int32 Iterations);
  1429.  
  1430.     /** @note Movement update functions should only be called through StartNewPhysics()*/
  1431.     virtual void PhysSwimming(float deltaTime, int32 Iterations);
  1432.  
  1433.     /** @note Movement update functions should only be called through StartNewPhysics()*/
  1434.     virtual void PhysCustom(float deltaTime, int32 Iterations);
  1435.  
  1436.     /**
  1437.     * Compute a vector of movement, given a delta and a hit result of the surface we are on.
  1438.     *
  1439.     * @param Delta:             Attempted movement direction
  1440.     * @param DeltaPlaneNormal:      Normal of the plane that contains Delta
  1441.     * @param RampHit:               Hit result of sweep that found the ramp below the capsule
  1442.     * @param bHitFromLineTrace: Whether the floor trace came from a line trace
  1443.     *
  1444.     * @return If on a walkable surface, this returns a vector that moves parallel to the surface. The magnitude may be scaled if bMaintainHorizontalGroundVelocity is true.
  1445.     * If a ramp vector can't be computed, this will just return Delta.
  1446.     */
  1447.     virtual FVector ComputeGroundMovementDelta(const FVector& Delta, const FVector& DeltaPlaneNormal, const FHitResult& RampHit, const bool bHitFromLineTrace) const;
  1448.  
  1449.     /**
  1450.     * Move along the floor, using CurrentFloor and ComputeGroundMovementDelta() to get a movement direction.
  1451.     * If a second walkable surface is hit, it will also be moved along using the same approach.
  1452.     *
  1453.     * @param InVelocity:            Velocity of movement
  1454.     * @param DeltaSeconds:          Time over which movement occurs
  1455.     * @param OutStepDownResult: [Out] If non-null, and a floor check is performed, this will be updated to reflect that result.
  1456.     */
  1457.     virtual void MoveAlongFloor(const FVector& InVelocity, float DeltaSeconds, FStepDownResult* OutStepDownResult = NULL);
  1458.  
  1459.     /** Notification that the character is stuck in geometry.  Only called during walking movement. */
  1460.     virtual void OnCharacterStuckInGeometry();
  1461.  
  1462.     /**
  1463.     * Adjusts velocity when walking so that Z velocity is zero.
  1464.     * When bMaintainHorizontalGroundVelocity is false, also rescales the velocity vector to maintain the original magnitude, but in the horizontal direction.
  1465.     */
  1466.     virtual void MaintainHorizontalGroundVelocity();
  1467.  
  1468.     /** Overridden to set bJustTeleported to true, so we don't make incorrect velocity calculations based on adjusted movement. */
  1469.     virtual bool ResolvePenetrationImpl(const FVector& Adjustment, const FHitResult& Hit, const FQuat& NewRotation) override;
  1470.  
  1471.     /** Handle a blocking impact. Calls ApplyImpactPhysicsForces for the hit, if bEnablePhysicsInteraction is true. */
  1472.     virtual void HandleImpact(const FHitResult& Impact, float TimeSlice = 0.f, const FVector& MoveDelta = FVector::ZeroVector) override;
  1473.  
  1474.     /**
  1475.     * Apply physics forces to the impacted component, if bEnablePhysicsInteraction is true.
  1476.     * @param Impact             HitResult that resulted in the impact
  1477.     * @param ImpactAcceleration Acceleration of the character at the time of impact
  1478.     * @param ImpactVelocity     Velocity of the character at the time of impact
  1479.     */
  1480.     virtual void ApplyImpactPhysicsForces(const FHitResult& Impact, const FVector& ImpactAcceleration, const FVector& ImpactVelocity);
  1481.  
  1482.     /** Custom version of SlideAlongSurface that handles different movement modes separately; namely during walking physics we might not want to slide up slopes. */
  1483.     virtual float SlideAlongSurface(const FVector& Delta, float Time, const FVector& Normal, FHitResult& Hit, bool bHandleImpact) override;
  1484.  
  1485.     /** Custom version that allows upwards slides when walking if the surface is walkable. */
  1486.     virtual void TwoWallAdjust(FVector& Delta, const FHitResult& Hit, const FVector& OldHitNormal) const override;
  1487.  
  1488.     /**
  1489.     * Calculate slide vector along a surface.
  1490.     * Has special treatment when falling, to avoid boosting up slopes (calling HandleSlopeBoosting() in this case).
  1491.     *
  1492.     * @param Delta: Attempted move.
  1493.     * @param Time:      Amount of move to apply (between 0 and 1).
  1494.     * @param Normal:    Normal opposed to movement. Not necessarily equal to Hit.Normal (but usually is).
  1495.     * @param Hit:       HitResult of the move that resulted in the slide.
  1496.     * @return           New deflected vector of movement.
  1497.     */
  1498.     virtual FVector ComputeSlideVector(const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const override;
  1499.  
  1500.     /**
  1501.     * (DEPRECATED) Given an upward impact on the top of the capsule, allows calculation of a different movement delta.
  1502.     */
  1503.     DEPRECATED(4.6, "AdjustUpperHemisphereImpact() is deprecated, for custom behavior override ComputeSlideVector() instead.")
  1504.         virtual FVector AdjustUpperHemisphereImpact(const FVector& Delta, const FHitResult& Hit) const;
  1505.  
  1506.     /**
  1507.     * Limit the slide vector when falling if the resulting slide might boost the character faster upwards.
  1508.     * @param SlideResult:   Vector of movement for the slide (usually the result of ComputeSlideVector)
  1509.     * @param Delta:     Original attempted move
  1510.     * @param Time:          Amount of move to apply (between 0 and 1).
  1511.     * @param Normal:        Normal opposed to movement. Not necessarily equal to Hit.Normal (but usually is).
  1512.     * @param Hit:           HitResult of the move that resulted in the slide.
  1513.     * @return:              New slide result.
  1514.     */
  1515.     virtual FVector HandleSlopeBoosting(const FVector& SlideResult, const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const;
  1516.  
  1517.     /** Slows towards stop. */
  1518.     virtual void ApplyVelocityBraking(float DeltaTime, float Friction, float BrakingDeceleration);
  1519.  
  1520.     /**
  1521.     * Return true if the 2D distance to the impact point is inside the edge tolerance (CapsuleRadius minus a small rejection threshold).
  1522.     * Useful for rejecting adjacent hits when finding a floor or landing spot.
  1523.     */
  1524.     virtual bool IsWithinEdgeTolerance(const FVector& CapsuleLocation, const FVector& CapsuleDown, const FVector& TestImpactPoint, const float CapsuleRadius) const;
  1525.  
  1526.     /**
  1527.     * Sweeps a vertical trace to find the floor for the capsule at the given location. Will attempt to perch if ShouldComputePerchResult() returns true for the downward sweep result.
  1528.     *
  1529.     * @param CapsuleLocation:       Location where the capsule sweep should originate
  1530.     * @param OutFloorResult:        [Out] Contains the result of the floor check. The HitResult will contain the valid sweep or line test upon success, or the result of the sweep upon failure.
  1531.     * @param bZeroDelta:            If true, the capsule was not actively moving in this update (can be used to avoid unnecessary floor tests).
  1532.     * @param DownwardSweepResult:   If non-null and it contains valid blocking hit info, this will be used as the result of a downward sweep test instead of doing it as part of the update.
  1533.     */
  1534.     virtual void FindFloor(const FVector& CapsuleLocation, struct FFindFloorResult& OutFloorResult, bool bZeroDelta, const FHitResult* DownwardSweepResult = NULL) const;
  1535.  
  1536.     /**
  1537.     * Compute distance to the floor from bottom sphere of capsule and store the result in OutFloorResult.
  1538.     * This distance is the swept distance of the capsule to the first point impacted by the lower hemisphere, or distance from the bottom of the capsule in the case of a line trace.
  1539.     * SweepDistance MUST be greater than or equal to the line distance.
  1540.     * @see FindFloor
  1541.     *
  1542.     * @param CapsuleLocation:   Location of the capsule used for the query
  1543.     * @param LineDistance:      If non-zero, max distance to test for a simple line check from the capsule base. Used only if the sweep test fails to find a walkable floor, and only returns a valid result if the impact normal is a walkable normal.
  1544.     * @param SweepDistance: If non-zero, max distance to use when sweeping a capsule downwards for the test.
  1545.     * @param OutFloorResult:    Result of the floor check. The HitResult will contain the valid sweep or line test upon success, or the result of the sweep upon failure.
  1546.     * @param SweepRadius:       The radius to use for sweep tests. Should be <= capsule radius.
  1547.     * @param DownwardSweepResult:   If non-null and it contains valid blocking hit info, this will be used as the result of a downward sweep test instead of doing it as part of the update.
  1548.     */
  1549.     virtual void ComputeFloorDist(const FVector& CapsuleLocation, float LineDistance, float SweepDistance, FFindFloorResult& OutFloorResult, float SweepRadius, const FHitResult* DownwardSweepResult = NULL) const;
  1550.  
  1551.     /**
  1552.     * Sweep against the world and return the first blocking hit.
  1553.     * Intended for tests against the floor, because it may change the result of impacts on the lower area of the test (especially if bUseFlatBaseForFloorChecks is true).
  1554.     *
  1555.     * @param OutHit         First blocking hit found.
  1556.     * @param Start              Start location of the capsule.
  1557.     * @param End                End location of the capsule.
  1558.     * @param TraceChannel       The 'channel' that this trace is in, used to determine which components to hit.
  1559.     * @param CollisionShape Capsule collision shape.
  1560.     * @param Params         Additional parameters used for the trace.
  1561.     * @param ResponseParam      ResponseContainer to be used for this trace.
  1562.     * @return True if OutHit contains a blocking hit entry.
  1563.     */
  1564.     virtual bool FloorSweepTest(
  1565.     struct FHitResult& OutHit,
  1566.         const FVector& Start,
  1567.         const FVector& End,
  1568.         ECollisionChannel TraceChannel,
  1569.         const struct FCollisionShape& CollisionShape,
  1570.         const struct FCollisionQueryParams& Params,
  1571.         const struct FCollisionResponseParams& ResponseParam
  1572.         ) const;
  1573.  
  1574.     /** Verify that the supplied hit result is a valid landing spot when falling. */
  1575.     virtual bool IsValidLandingSpot(const FVector& CapsuleLocation, const FHitResult& Hit) const;
  1576.  
  1577.     /**
  1578.     * Determine whether we should try to find a valid landing spot after an impact with an invalid one (based on the Hit result).
  1579.     * For example, landing on the lower portion of the capsule on the edge of geometry may be a walkable surface, but could have reported an unwalkable impact normal.
  1580.     */
  1581.     virtual bool ShouldCheckForValidLandingSpot(float DeltaTime, const FVector& Delta, const FHitResult& Hit) const;
  1582.  
  1583.     /**
  1584.     * Check if the result of a sweep test (passed in InHit) might be a valid location to perch, in which case we should use ComputePerchResult to validate the location.
  1585.     * @see ComputePerchResult
  1586.     * @param InHit:         Result of the last sweep test before this query.
  1587.     * @param bCheckRadius:      If true, only allow the perch test if the impact point is outside the radius returned by GetValidPerchRadius().
  1588.     * @return Whether perching may be possible, such that ComputePerchResult can return a valid result.
  1589.     */
  1590.     virtual bool ShouldComputePerchResult(const FHitResult& InHit, bool bCheckRadius = true) const;
  1591.  
  1592.     /**
  1593.     * Compute the sweep result of the smaller capsule with radius specified by GetValidPerchRadius(),
  1594.     * and return true if the sweep contacts a valid walkable normal within InMaxFloorDist of InHit.ImpactPoint.
  1595.     * This may be used to determine if the capsule can or cannot stay at the current location if perched on the edge of a small ledge or unwalkable surface.
  1596.     * Note: Only returns a valid result if ShouldComputePerchResult returned true for the supplied hit value.
  1597.     *
  1598.     * @param TestRadius:            Radius to use for the sweep, usually GetValidPerchRadius().
  1599.     * @param InHit:             Result of the last sweep test before the query.
  1600.     * @param InMaxFloorDist:        Max distance to floor allowed by perching, from the supplied contact point (InHit.ImpactPoint).
  1601.     * @param OutPerchFloorResult:   Contains the result of the perch floor test.
  1602.     * @return True if the current location is a valid spot at which to perch.
  1603.     */
  1604.     virtual bool ComputePerchResult(const float TestRadius, const FHitResult& InHit, const float InMaxFloorDist, FFindFloorResult& OutPerchFloorResult) const;
  1605.  
  1606.     /** Called when the collision capsule touches another primitive component */
  1607.     UFUNCTION()
  1608.         virtual void CapsuleTouched(AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
  1609.  
  1610.     // Enum used to control GetPawnCapsuleExtent behavior
  1611.     enum EShrinkCapsuleExtent
  1612.     {
  1613.         SHRINK_None,            // Don't change the size of the capsule
  1614.         SHRINK_RadiusCustom,    // Change only the radius, based on a supplied param
  1615.         SHRINK_HeightCustom,    // Change only the height, based on a supplied param
  1616.         SHRINK_AllCustom,       // Change both radius and height, based on a supplied param
  1617.     };
  1618.  
  1619.     /** Get the capsule extent for the Pawn owner, possibly reduced in size depending on ShrinkMode.
  1620.     * @param ShrinkMode         Controls the way the capsule is resized.
  1621.     * @param CustomShrinkAmount The amount to shrink the capsule, used only for ShrinkModes that specify custom.
  1622.     * @return The capsule extent of the Pawn owner, possibly reduced in size depending on ShrinkMode.
  1623.     */
  1624.     FVector GetPawnCapsuleExtent(const EShrinkCapsuleExtent ShrinkMode, const float CustomShrinkAmount = 0.f) const;
  1625.  
  1626.     /** Get the collision shape for the Pawn owner, possibly reduced in size depending on ShrinkMode.
  1627.     * @param ShrinkMode         Controls the way the capsule is resized.
  1628.     * @param CustomShrinkAmount The amount to shrink the capsule, used only for ShrinkModes that specify custom.
  1629.     * @return The capsule extent of the Pawn owner, possibly reduced in size depending on ShrinkMode.
  1630.     */
  1631.     FCollisionShape GetPawnCapsuleCollisionShape(const EShrinkCapsuleExtent ShrinkMode, const float CustomShrinkAmount = 0.f) const;
  1632.  
  1633.     /** Adjust the size of the capsule on simulated proxies, to avoid overlaps due to replication rounding.
  1634.     * Changes to the capsule size on the proxy should set bShrinkProxyCapsule=true and possibly call AdjustProxyCapsuleSize() immediately if applicable.
  1635.     */
  1636.     virtual void AdjustProxyCapsuleSize();
  1637.  
  1638.     /** Enforce constraints on input given current state. For instance, don't move upwards if walking and looking up. */
  1639.     virtual FVector ConstrainInputAcceleration(const FVector& InputAcceleration) const;
  1640.  
  1641.     /** Scale input acceleration, based on movement acceleration rate. */
  1642.     virtual FVector ScaleInputAcceleration(const FVector& InputAcceleration) const;
  1643.  
  1644.     /**
  1645.     * Event triggered at the end of a movement update. If scoped movement updates are enabled (bEnableScopedMovementUpdates), this is within such a scope.
  1646.     * If that is not desired, bind to the CharacterOwner's OnMovementUpdated event instead, as that is triggered after the scoped movement update.
  1647.     */
  1648.     virtual void OnMovementUpdated(float DeltaSeconds, const FVector& OldLocation, const FVector& OldVelocity);
  1649.  
  1650.     /** Internal function to call OnMovementUpdated delegate on CharacterOwner. */
  1651.     virtual void CallMovementUpdateDelegate(float DeltaSeconds, const FVector& OldLocation, const FVector& OldVelocity);
  1652.  
  1653.     /**
  1654.     * Event triggered when we are moving on a base but we are not able to move the full DeltaPosition because something has blocked us.
  1655.     * Note: MoveComponentFlags includes the flag to ignore the movement base while this event is fired.
  1656.     * @param DeltaPosition      How far we tried to move with the base.
  1657.     * @param OldLocation        Location before we tried to move with the base.
  1658.     * @param MoveOnBaseHit      Hit result for the object we hit when trying to move with the base.
  1659.     */
  1660.     virtual void OnUnableToFollowBaseMove(const FVector& DeltaPosition, const FVector& OldLocation, const FHitResult& MoveOnBaseHit);
  1661.  
  1662. public:
  1663.  
  1664.     /**
  1665.     * Project a location to navmesh to find adjusted height.
  1666.     * @param TestLocation       Location to project
  1667.     * @param NavFloorLocation   Location on navmesh
  1668.     * @return True if projection was performed (successfully or not)
  1669.     */
  1670.     bool FindNavFloor(const FVector& TestLocation, FNavLocation& NavFloorLocation) const;
  1671.  
  1672.     // Movement functions broken out based on owner's network Role.
  1673.     // TickComponent calls the correct version based on the Role.
  1674.     // These may be called during move playback and correction during network updates.
  1675.     //
  1676.  
  1677.     /** Perform movement on an autonomous client */
  1678.     virtual void PerformMovement(float DeltaTime);
  1679.  
  1680.     /** Special Tick for Simulated Proxies */
  1681.     void SimulatedTick(float DeltaSeconds);
  1682.  
  1683.     /** Simulate movement on a non-owning client. */
  1684.     virtual void SimulateMovement(float DeltaTime);
  1685.  
  1686.     /** Force a client update by making it appear on the server that the client hasn't updated in a long time. */
  1687.     virtual void ForceReplicationUpdate();
  1688.  
  1689.     /**
  1690.     * Generate a random angle in degrees that is approximately equal between client and server.
  1691.     * Note that in networked games this result changes with low frequency and has a low period,
  1692.     * so should not be used for frequent randomization.
  1693.     */
  1694.     virtual float GetNetworkSafeRandomAngleDegrees() const;
  1695.  
  1696.     /** Round acceleration, for better consistency and lower bandwidth in networked games. */
  1697.     virtual FVector RoundAcceleration(FVector InAccel) const;
  1698.  
  1699.     //--------------------------------
  1700.     // INetworkPredictionInterface implementation
  1701.  
  1702.     //--------------------------------
  1703.     // Server hook
  1704.     //--------------------------------
  1705.     virtual void SendClientAdjustment() override;
  1706.     virtual void ForcePositionUpdate(float DeltaTime) override;
  1707.  
  1708.     //--------------------------------
  1709.     // Client hook
  1710.     //--------------------------------
  1711.     virtual void SmoothCorrection(const FVector& OldLocation, const FQuat& OldRotation) override;
  1712.  
  1713.     virtual class FNetworkPredictionData_Client* GetPredictionData_Client() const override;
  1714.     virtual class FNetworkPredictionData_Server* GetPredictionData_Server() const override;
  1715.  
  1716.     virtual bool HasPredictionData_Client() const override { return ClientPredictionData != NULL; }
  1717.     virtual bool HasPredictionData_Server() const override { return ServerPredictionData != NULL; }
  1718.  
  1719.     virtual void ResetPredictionData_Client() override;
  1720.     virtual void ResetPredictionData_Server() override;
  1721.  
  1722. protected:
  1723.     class FNetworkPredictionData_Client_Character* ClientPredictionData;
  1724.     class FNetworkPredictionData_Server_Character* ServerPredictionData;
  1725.  
  1726.     virtual class FNetworkPredictionData_Client_Character* GetPredictionData_Client_Character() const;
  1727.     virtual class FNetworkPredictionData_Server_Character* GetPredictionData_Server_Character() const;
  1728.  
  1729.     virtual void SmoothClientPosition(float DeltaTime);
  1730.  
  1731.     /*
  1732.     ========================================================================
  1733.     Here's how player movement prediction, replication and correction works in network games:
  1734.  
  1735.     Every tick, the TickComponent() function is called.  It figures out the acceleration and rotation change for the frame,
  1736.     and then calls PerformMovement() (for locally controlled Characters), or ReplicateMoveToServer() (if it's a network client).
  1737.  
  1738.     ReplicateMoveToServer() saves the move (in the PendingMove list), calls PerformMovement(), and then replicates the move
  1739.     to the server by calling the replicated function ServerMove() - passing the movement parameters, the client's
  1740.     resultant position, and a timestamp.
  1741.  
  1742.     ServerMove() is executed on the server.  It decodes the movement parameters and causes the appropriate movement
  1743.     to occur.  It then looks at the resulting position and if enough time has passed since the last response, or the
  1744.     position error is significant enough, the server calls ClientAdjustPosition(), a replicated function.
  1745.  
  1746.     ClientAdjustPosition() is executed on the client.  The client sets its position to the servers version of position,
  1747.     and sets the bUpdatePosition flag to true.
  1748.  
  1749.     When TickComponent() is called on the client again, if bUpdatePosition is true, the client will call
  1750.     ClientUpdatePosition() before calling PerformMovement().  ClientUpdatePosition() replays all the moves in the pending
  1751.     move list which occurred after the timestamp of the move the server was adjusting.
  1752.     */
  1753.  
  1754.     /** Perform local movement and send the move to the server. */
  1755.     virtual void ReplicateMoveToServer(float DeltaTime, const FVector& NewAcceleration);
  1756.  
  1757.     /** If bUpdatePosition is true, then replay any unacked moves. Returns whether any moves were actually replayed. */
  1758.     virtual bool ClientUpdatePositionAfterServerUpdate();
  1759.  
  1760.     /** Call the appropriate replicated servermove() function to send a client player move to the server. */
  1761.     virtual void CallServerMove(const class FSavedMove_Character* NewMove, const class FSavedMove_Character* OldMove);
  1762.  
  1763.     /**
  1764.     * Have the server check if the client is outside an error tolerance, and queue a client adjustment if so.
  1765.     * If either GetPredictionData_Server_Character()->bForceClientUpdate or ServerCheckClientError() are true, the client adjustment will be sent.
  1766.     * RelativeClientLocation will be a relative location if MovementBaseUtility::UseRelativePosition(ClientMovementBase) is true, or a world location if false.
  1767.     * @see ServerCheckClientError()
  1768.     */
  1769.     virtual void ServerMoveHandleClientError(float ClientTimeStamp, float DeltaTime, const FVector& Accel, const FVector& RelativeClientLocation, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1770.  
  1771.     /**
  1772.     * Check for Server-Client disagreement in position or other movement state important enough to trigger a client correction.
  1773.     * @see ServerMoveHandleClientError()
  1774.     */
  1775.     virtual bool ServerCheckClientError(float ClientTimeStamp, float DeltaTime, const FVector& Accel, const FVector& ClientWorldLocation, const FVector& RelativeClientLocation, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1776.  
  1777.     /* Process a move at the given time stamp, given the compressed flags representing various events that occurred (ie jump). */
  1778.     virtual void MoveAutonomous( float ClientTimeStamp, float DeltaTime, uint8 CompressedFlags, const FVector& NewAccel);
  1779.  
  1780.     /** Unpack compressed flags from a saved move and set state accordingly. See FSavedMove_Character. */
  1781.     virtual void UpdateFromCompressedFlags(uint8 Flags);
  1782.  
  1783.     /** Return true if it is OK to delay sending this player movement to the server, in order to conserve bandwidth. */
  1784.     virtual bool CanDelaySendingMove(const FSavedMovePtr& NewMove);
  1785.  
  1786.     /** Ticks the characters pose and accumulates root motion */
  1787.     void TickCharacterPose(float DeltaTime);
  1788.  
  1789. public:
  1790.  
  1791.     /** React to instantaneous change in position. Invalidates cached floor recomputes it if possible if there is a current movement base. */
  1792.     virtual void UpdateFloorFromAdjustment();
  1793.  
  1794.     /** Minimum time between client TimeStamp resets.
  1795.     !! This has to be large enough so that we don't confuse the server if the client can stall or timeout.
  1796.     We do this as we use floats for TimeStamps, and server derives DeltaTime from two TimeStamps.
  1797.     As time goes on, accuracy decreases from those floating point numbers.
  1798.     So we trigger a TimeStamp reset at regular intervals to maintain a high level of accuracy. */
  1799.     UPROPERTY()
  1800.         float MinTimeBetweenTimeStampResets;
  1801.  
  1802.     /** On the Server, verify that an incoming client TimeStamp is valid and has not yet expired.
  1803.     It will also handle TimeStamp resets if it detects a gap larger than MinTimeBetweenTimeStampResets / 2.f
  1804.     !! ServerData.CurrentClientTimeStamp can be reset !!
  1805.     @returns true if TimeStamp is valid, or false if it has expired. */
  1806.     bool VerifyClientTimeStamp(float TimeStamp, FNetworkPredictionData_Server_Character & ServerData);
  1807.  
  1808.     ////////////////////////////////////
  1809.     // Network RPCs for movement
  1810.     ////////////////////////////////////
  1811.  
  1812.     /** Replicated function sent by client to server - contains client movement and view info. */
  1813.     UFUNCTION(unreliable, server, WithValidation)
  1814.         virtual void ServerMove(float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 CompressedMoveFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1815.     virtual void ServerMove_Implementation(float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 CompressedMoveFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1816.     virtual bool ServerMove_Validate(float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 CompressedMoveFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1817.  
  1818.     /** Replicated function sent by client to server - contains client movement and view info for two moves. */
  1819.     UFUNCTION(unreliable, server, WithValidation)
  1820.         virtual void ServerMoveDual(float TimeStamp0, FVector_NetQuantize10 InAccel0, uint8 PendingFlags, uint32 View0, float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 NewFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1821.     virtual void ServerMoveDual_Implementation(float TimeStamp0, FVector_NetQuantize10 InAccel0, uint8 PendingFlags, uint32 View0, float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 NewFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1822.     virtual bool ServerMoveDual_Validate(float TimeStamp0, FVector_NetQuantize10 InAccel0, uint8 PendingFlags, uint32 View0, float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 NewFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1823.  
  1824.     /** Replicated function sent by client to server - contains client movement and view info for two moves. First move is non root motion, second is root motion. */
  1825.     UFUNCTION(unreliable, server, WithValidation)
  1826.     virtual void ServerMoveDualHybridRootMotion(float TimeStamp0, FVector_NetQuantize10 InAccel0, uint8 PendingFlags, uint32 View0, float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 NewFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1827.     virtual void ServerMoveDualHybridRootMotion_Implementation(float TimeStamp0, FVector_NetQuantize10 InAccel0, uint8 PendingFlags, uint32 View0, float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 NewFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1828.     virtual bool ServerMoveDualHybridRootMotion_Validate(float TimeStamp0, FVector_NetQuantize10 InAccel0, uint8 PendingFlags, uint32 View0, float TimeStamp, FVector_NetQuantize10 InAccel, FVector_NetQuantize100 ClientLoc, uint8 NewFlags, uint8 ClientRoll, uint32 View, UPrimitiveComponent* ClientMovementBase, FName ClientBaseBoneName, uint8 ClientMovementMode);
  1829.  
  1830.     /* Resending an (important) old move. Process it if not already processed. */
  1831.     UFUNCTION(unreliable, server, WithValidation)
  1832.         virtual void ServerMoveOld(float OldTimeStamp, FVector_NetQuantize10 OldAccel, uint8 OldMoveFlags);
  1833.     virtual void ServerMoveOld_Implementation(float OldTimeStamp, FVector_NetQuantize10 OldAccel, uint8 OldMoveFlags);
  1834.     virtual bool ServerMoveOld_Validate(float OldTimeStamp, FVector_NetQuantize10 OldAccel, uint8 OldMoveFlags);
  1835.  
  1836.     /** If no client adjustment is needed after processing received ServerMove(), ack the good move so client can remove it from SavedMoves */
  1837.     UFUNCTION(unreliable, client)
  1838.         virtual void ClientAckGoodMove(float TimeStamp);
  1839.     virtual void ClientAckGoodMove_Implementation(float TimeStamp);
  1840.  
  1841.     /** Replicate position correction to client, associated with a timestamped servermove.  Client will replay subsequent moves after applying adjustment.  */
  1842.     UFUNCTION(unreliable, client)
  1843.         virtual void ClientAdjustPosition(float TimeStamp, FVector NewLoc, FVector NewVel, UPrimitiveComponent* NewBase, FName NewBaseBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
  1844.     virtual void ClientAdjustPosition_Implementation(float TimeStamp, FVector NewLoc, FVector NewVel, UPrimitiveComponent* NewBase, FName NewBaseBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
  1845.  
  1846.     /* Bandwidth saving version, when velocity is zeroed */
  1847.     UFUNCTION(unreliable, client)
  1848.         virtual void ClientVeryShortAdjustPosition(float TimeStamp, FVector NewLoc, UPrimitiveComponent* NewBase, FName NewBaseBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
  1849.     virtual void ClientVeryShortAdjustPosition_Implementation(float TimeStamp, FVector NewLoc, UPrimitiveComponent* NewBase, FName NewBaseBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
  1850.  
  1851.     /** Replicate position correction to client when using root motion for movement. */
  1852.     UFUNCTION(unreliable, client)
  1853.         void ClientAdjustRootMotionPosition(float TimeStamp, float ServerMontageTrackPosition, FVector ServerLoc, FVector_NetQuantizeNormal ServerRotation, float ServerVelZ, UPrimitiveComponent* ServerBase, FName ServerBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
  1854.     void ClientAdjustRootMotionPosition_Implementation(float TimeStamp, float ServerMontageTrackPosition, FVector ServerLoc, FVector_NetQuantizeNormal ServerRotation, float ServerVelZ, UPrimitiveComponent* ServerBase, FName ServerBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode);
  1855.  
  1856.     // Root Motion
  1857. public:
  1858.     /** Root Motion movement params */
  1859.     UPROPERTY(Transient)
  1860.         FRootMotionMovementParams RootMotionParams;
  1861.  
  1862.     /** True when SimulatedProxies are simulating RootMotion */
  1863.     UPROPERTY(Transient)
  1864.         bool bWasSimulatingRootMotion;
  1865.  
  1866.     /** @return true if we have Root Motion to use in PerformMovement() physics.
  1867.     Not valid outside of the scope of that function. Since RootMotion is extracted and used in it. */
  1868.     bool HasRootMotion() const
  1869.     {
  1870.         return RootMotionParams.bHasRootMotion;
  1871.     }
  1872.  
  1873.     /** Simulate Root Motion physics on Simulated Proxies */
  1874.     void SimulateRootMotion(float DeltaSeconds, const FTransform& LocalRootMotionTransform);
  1875.  
  1876.     /**
  1877.     * Calculate velocity from root motion. Under some movement conditions, only portions of root motion may be used (e.g. when falling Z may be ignored).
  1878.     * @param RootMotionDeltaMove    Change in location from root motion.
  1879.     * @param DeltaSeconds           Elapsed time
  1880.     * @param CurrentVelocity        Non-root motion velocity at current time, used for components of result that may ignore root motion.
  1881.     */
  1882.     virtual FVector CalcRootMotionVelocity(const FVector& RootMotionDeltaMove, float DeltaSeconds, const FVector& CurrentVelocity) const;
  1883.  
  1884.     // RVO Avoidance
  1885.  
  1886.     /** calculate RVO avoidance and apply it to current velocity */
  1887.     virtual void CalcAvoidanceVelocity(float DeltaTime);
  1888.  
  1889.     /** allows modifing avoidance velocity, called when bUseRVOPostProcess is set */
  1890.     virtual void PostProcessAvoidanceVelocity(FVector& NewVelocity);
  1891.  
  1892. protected:
  1893.  
  1894.     /** called in Tick to update data in RVO avoidance manager */
  1895.     void UpdateDefaultAvoidance();
  1896.  
  1897.     /** lock avoidance velocity */
  1898.     void SetAvoidanceVelocityLock(class UAvoidanceManager* Avoidance, float Duration);
  1899.  
  1900.     /** BEGIN IRVOAvoidanceInterface */
  1901.     virtual void SetRVOAvoidanceUID(int32 UID) override;
  1902.     virtual int32 GetRVOAvoidanceUID() override;
  1903.     virtual void SetRVOAvoidanceWeight(float Weight) override;
  1904.     virtual float GetRVOAvoidanceWeight() override;
  1905.     virtual FVector GetRVOAvoidanceOrigin() override;
  1906.     virtual float GetRVOAvoidanceRadius() override;
  1907.     virtual float GetRVOAvoidanceHeight() override;
  1908.     virtual float GetRVOAvoidanceConsiderationRadius() override;
  1909.     virtual FVector GetVelocityForRVOConsideration() override;
  1910.     virtual int32 GetAvoidanceGroupMask() override;
  1911.     virtual int32 GetGroupsToAvoidMask() override;
  1912.     virtual int32 GetGroupsToIgnoreMask() override;
  1913.     /** END IRVOAvoidanceInterface */
  1914.  
  1915. public:
  1916.  
  1917.     /** Minimum delta time considered when ticking. Delta times below this are not considered. This is a very small non-zero value to avoid potential divide-by-zero in simulation code. */
  1918.     static const float MIN_TICK_TIME;
  1919.  
  1920.     /** Minimum acceptable distance for Character capsule to float above floor when walking. */
  1921.     static const float MIN_FLOOR_DIST;
  1922.  
  1923.     /** Maximum acceptable distance for Character capsule to float above floor when walking. */
  1924.     static const float MAX_FLOOR_DIST;
  1925.  
  1926.     /** Reject sweep impacts that are this close to the edge of the vertical portion of the capsule when performing vertical sweeps, and try again with a smaller capsule. */
  1927.     static const float SWEEP_EDGE_REJECT_DISTANCE;
  1928.  
  1929.     /** Stop completely when braking and velocity magnitude is lower than this. */
  1930.     static const float BRAKE_TO_STOP_VELOCITY;
  1931.  
  1932. protected:
  1933.     /**
  1934.     * Moves our UpdatedComponent by the given Delta, and sets rotation to NewRotation.
  1935.     * Respects the plane constraint, if enabled.
  1936.     * @return True if some movement occurred, false if no movement occurred. Result of any impact will be stored in OutHit.
  1937.     */
  1938.     virtual bool MoveUpdatedComponent(const FVector& Delta, const FRotator& NewRotation, bool bSweep, FHitResult* OutHit = NULL);
  1939.  
  1940. public:
  1941.     /**
  1942.     * Calculate a constrained rotation for the updated component.
  1943.     *
  1944.     * @param Rotation - Initial rotation.
  1945.     * @return New rotation to use.
  1946.     */
  1947.     virtual FRotator ConstrainComponentRotation(const FRotator& Rotation) const;
  1948.  
  1949.     /**
  1950.     * Return the desired local Z rotation axis wanted for the updated component.
  1951.     *
  1952.     * @return Desired Z rotation axis.
  1953.     */
  1954.     virtual FVector GetComponentDesiredAxisZ() const;
  1955.  
  1956.     /**
  1957.     * Update the rotation of the updated component.
  1958.     */
  1959.     virtual void UpdateComponentRotation();
  1960.  
  1961. protected:
  1962.     /**
  1963.     * Get the current rotation of the collision capsule.
  1964.     *
  1965.     * @return Quaternion representation of capsule rotation.
  1966.     */
  1967.     FORCEINLINE FQuat GetCapsuleRotation() const;
  1968.  
  1969.     /**
  1970.     * Return the current local X rotation axis of the updated component.
  1971.     *
  1972.     * @return Current X rotation axis of capsule.
  1973.     */
  1974.     FORCEINLINE FVector GetCapsuleAxisX() const;
  1975.  
  1976.     /**
  1977.     * Return the current local Z rotation axis of the updated component.
  1978.     *
  1979.     * @return Current Z rotation axis of capsule.
  1980.     */
  1981.     FORCEINLINE FVector GetCapsuleAxisZ() const;
  1982.  
  1983. protected:
  1984.     /**
  1985.     * Custom gravity direction.
  1986.     */
  1987.     UPROPERTY()
  1988.         FVector CustomGravityDirection;
  1989.  
  1990. public:
  1991.     /**
  1992.     * Update values related to gravity.
  1993.     *
  1994.     * @param DeltaTime - Time elapsed since last frame.
  1995.     */
  1996.     virtual void UpdateGravity(float DeltaTime);
  1997.  
  1998.     /**
  1999.     * Return the current gravity.
  2000.     * @note Could return zero gravity.
  2001.     *
  2002.     * @return Current gravity.
  2003.     */
  2004.     virtual FVector GetGravity() const;
  2005.  
  2006.     /**
  2007.     * Return the normalized direction of the current gravity.
  2008.     * @note Could return zero gravity.
  2009.     *
  2010.     * @param bAvoidZeroGravity - If true, zero gravity isn't returned.
  2011.     * @return Normalized direction of current gravity.
  2012.     */
  2013.     UFUNCTION(Category = "Pawn|Components|CharacterMovement", BlueprintCallable)
  2014.         virtual FVector GetGravityDirection(bool bAvoidZeroGravity = false) const;
  2015.  
  2016.     /**
  2017.     * Return the absolute magnitude of the current gravity.
  2018.     *
  2019.     * @return Magnitude of current gravity.
  2020.     */
  2021.     UFUNCTION(Category = "Pawn|Components|CharacterMovement", BlueprintCallable)
  2022.         virtual float GetGravityMagnitude() const;
  2023.  
  2024.     /**
  2025.     * Set a custom gravity direction; use 0,0,0 to remove any custom direction.
  2026.     * @note It can be influenced by GravityScale.
  2027.     *
  2028.     * @param NewGravityDirection - New gravity direction, assumes it isn't normalized.
  2029.     */
  2030.     UFUNCTION(Category = "Pawn|Components|CharacterMovement", BlueprintCallable)
  2031.         virtual void SetGravityDirection(FVector NewGravityDirection);
  2032. };
  2033.  
  2034.  
  2035. FORCEINLINE ACharacter* UCharacterMovementComponent::GetCharacterOwner() const
  2036. {
  2037.     return CharacterOwner;
  2038. }
  2039.  
  2040. FORCEINLINE_DEBUGGABLE bool UCharacterMovementComponent::IsWalking() const
  2041. {
  2042.     return IsMovingOnGround();
  2043. }
  2044.  
  2045.  
  2046.  
  2047. /** FSavedMove_Character represents a saved move on the client that has been sent to the server and might need to be played back. */
  2048. class ENGINE_API FSavedMove_Character
  2049. {
  2050. public:
  2051.     FSavedMove_Character();
  2052.     virtual ~FSavedMove_Character();
  2053.  
  2054.     uint32 bPressedJump : 1;
  2055.     uint32 bWantsToCrouch : 1;
  2056.     uint32 bForceMaxAccel : 1;
  2057.  
  2058.     /** If true, can't combine this move with another move. */
  2059.     uint32 bForceNoCombine : 1;
  2060.  
  2061.     /** If true this move is using an old TimeStamp, before a reset occurred. */
  2062.     uint32 bOldTimeStampBeforeReset : 1;
  2063.  
  2064.     float TimeStamp;    // Time of this move.
  2065.     float DeltaTime;    // amount of time for this move
  2066.     float CustomTimeDilation;
  2067.     float JumpKeyHoldTime;
  2068.     uint8 MovementMode; // packed movement mode
  2069.  
  2070.     // Information at the start of the move
  2071.     FVector StartLocation;
  2072.     FVector StartRelativeLocation;
  2073.     FVector StartVelocity;
  2074.     FFindFloorResult StartFloor;
  2075.     FRotator StartRotation;
  2076.     FRotator StartControlRotation;
  2077.     FQuat StartBaseRotation;    // rotation of the base component (or bone), only saved if it can move.
  2078.     float StartCapsuleRadius;
  2079.     float StartCapsuleHalfHeight;
  2080.     TWeakObjectPtr<UPrimitiveComponent> StartBase;
  2081.     FName StartBoneName;
  2082.  
  2083.     // Information after the move has been performed
  2084.     FVector SavedLocation;
  2085.     FRotator SavedRotation;
  2086.     FVector SavedVelocity;
  2087.     FVector SavedRelativeLocation;
  2088.     FRotator SavedControlRotation;
  2089.     TWeakObjectPtr<UPrimitiveComponent> EndBase;
  2090.     FName EndBoneName;
  2091.  
  2092.     FVector Acceleration;
  2093.  
  2094.     // Cached to speed up iteration over IsImportantMove().
  2095.     FVector AccelNormal;
  2096.     float AccelMag;
  2097.  
  2098.     TWeakObjectPtr<class UAnimMontage> RootMotionMontage;
  2099.     float RootMotionTrackPosition;
  2100.     FRootMotionMovementParams RootMotionMovement;
  2101.  
  2102.     /** Threshold for deciding this is an "important" move based on DP with last acked acceleration. */
  2103.     float AccelDotThreshold;
  2104.     /** Threshold for deciding is this is an important move because acceleration magnitude has changed too much */
  2105.     float AccelMagThreshold;
  2106.     /** Threshold for deciding if we can combine two moves, true if cosine of angle between them is <= this. */
  2107.     float AccelDotThresholdCombine;
  2108.  
  2109.     /** Clear saved move properties, so it can be re-used. */
  2110.     virtual void Clear();
  2111.  
  2112.     /** Called to set up this saved move (when initially created) to make a predictive correction. */
  2113.     virtual void SetMoveFor(ACharacter* C, float DeltaTime, FVector const& NewAccel, class FNetworkPredictionData_Client_Character & ClientData);
  2114.  
  2115.     /** Set the properties describing the position, etc. of the moved pawn at the start of the move. */
  2116.     virtual void SetInitialPosition(ACharacter* C);
  2117.  
  2118.     /** @Return true if this move is an "important" move that should be sent again if not acked by the server */
  2119.     virtual bool IsImportantMove(const FSavedMovePtr& LastAckedMove) const;
  2120.  
  2121.     /** Returns starting position if we were to revert the move, either absolute StartLocation, or StartRelativeLocation offset from MovementBase's current location (since we want to try to move forward at this time). */
  2122.     virtual FVector GetRevertedLocation() const;
  2123.  
  2124.     enum EPostUpdateMode
  2125.     {
  2126.         PostUpdate_Record,      // Record a move after having run the simulation
  2127.         PostUpdate_Replay,      // Update after replaying a move for a client correction
  2128.     };
  2129.  
  2130.     /** Set the properties describing the final position, etc. of the moved pawn. */
  2131.     virtual void PostUpdate(ACharacter* C, EPostUpdateMode PostUpdateMode);
  2132.  
  2133.     /** @Return true if this move can be combined with NewMove for replication without changing any behavior */
  2134.     virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InPawn, float MaxDelta) const;
  2135.  
  2136.     /** Called before ClientUpdatePosition uses this SavedMove to make a predictive correction   */
  2137.     virtual void PrepMoveFor(ACharacter* C);
  2138.  
  2139.     /** @returns a byte containing encoded special movement information (jumping, crouching, etc.)   */
  2140.     virtual uint8 GetCompressedFlags() const;
  2141.  
  2142.     // Bit masks used by GetCompressedFlags() to encode movement information.
  2143.     enum CompressedFlags
  2144.     {
  2145.         FLAG_JumpPressed = 0x01,    // Jump pressed
  2146.         FLAG_WantsToCrouch = 0x02// Wants to crouch
  2147.         FLAG_Reserved_1 = 0x04, // Reserved for future use
  2148.         FLAG_Reserved_2 = 0x08, // Reserved for future use
  2149.         // Remaining bit masks are available for custom flags.
  2150.         FLAG_Custom_0 = 0x10,
  2151.         FLAG_Custom_1 = 0x20,
  2152.         FLAG_Custom_2 = 0x40,
  2153.         FLAG_Custom_3 = 0x80,
  2154.     };
  2155. };
  2156.  
  2157. // ClientAdjustPosition replication (event called at end of frame by server)
  2158. struct ENGINE_API FClientAdjustment
  2159. {
  2160. public:
  2161.  
  2162.     FClientAdjustment()
  2163.         : TimeStamp(0.f)
  2164.         , DeltaTime(0.f)
  2165.         , NewLoc(ForceInitToZero)
  2166.         , NewVel(ForceInitToZero)
  2167.         , NewRot(ForceInitToZero)
  2168.         , NewBase(NULL)
  2169.         , NewBaseBoneName(NAME_None)
  2170.         , bAckGoodMove(false)
  2171.         , bBaseRelativePosition(false)
  2172.         , MovementMode(0)
  2173.     {
  2174.     }
  2175.  
  2176.     float TimeStamp;
  2177.     float DeltaTime;
  2178.     FVector NewLoc;
  2179.     FVector NewVel;
  2180.     FRotator NewRot;
  2181.     UPrimitiveComponent* NewBase;
  2182.     FName NewBaseBoneName;
  2183.     bool bAckGoodMove;
  2184.     bool bBaseRelativePosition;
  2185.     uint8 MovementMode;
  2186. };
  2187.  
  2188. class ENGINE_API FNetworkPredictionData_Client_Character : public FNetworkPredictionData_Client
  2189. {
  2190. public:
  2191.  
  2192.     FNetworkPredictionData_Client_Character(const UCharacterMovementComponent& ClientMovement);
  2193.     virtual ~FNetworkPredictionData_Client_Character();
  2194.  
  2195.     /** Client timestamp of last time it sent a servermove() to the server.  Used for holding off on sending movement updates to save bandwidth. */
  2196.     float ClientUpdateTime;
  2197.  
  2198.     /** Current TimeStamp for sending new Moves to the Server. */
  2199.     float CurrentTimeStamp;
  2200.  
  2201.     TArray<FSavedMovePtr> SavedMoves;       // Buffered moves pending position updates, orderd oldest to newest. Moves that have been acked by the server are removed.
  2202.     TArray<FSavedMovePtr> FreeMoves;        // freed moves, available for buffering
  2203.     FSavedMovePtr PendingMove;              // PendingMove already processed on client - waiting to combine with next movement to reduce client to server bandwidth
  2204.     FSavedMovePtr LastAckedMove;            // Last acknowledged sent move.
  2205.  
  2206.     int32 MaxFreeMoveCount;                 // Limit on size of free list
  2207.     int32 MaxSavedMoveCount;                // Limit on the size of the saved move buffer
  2208.  
  2209.     uint32 bUpdatePosition : 1; // when true, update the position (via ClientUpdatePosition)
  2210.  
  2211.     /** RootMotion saved while animation is updated, so we can store it and replay if needed in case of a position correction. */
  2212.     FRootMotionMovementParams RootMotionMovement;
  2213.  
  2214.     // Mesh smoothing variables (for network smoothing)
  2215.     //
  2216.     /** Whether to smoothly interpolate pawn position corrections on clients based on received location updates */
  2217.     uint32 bSmoothNetUpdates : 1;
  2218.  
  2219.     /** Used for position smoothing in net games */
  2220.     FVector MeshTranslationOffset;
  2221.  
  2222.     /** Used for rotation smoothing in net games */
  2223.     FQuat MeshRotationOffset;
  2224.  
  2225.     /** Used for position smoothing in net games */
  2226.     FVector OriginalMeshTranslationOffset;
  2227.  
  2228.     /** Used for rotation smoothing in net games */
  2229.     FQuat OriginalMeshRotationOffset;
  2230.  
  2231.     /** Used for remembering how much time has passed between server corrections */
  2232.     float LastCorrectionDelta;
  2233.  
  2234.     /** Used to track how much time has elapsed since last correction */
  2235.     float CurrentSmoothTime;
  2236.  
  2237.     /** Used to signify that linear smoothing is desired */
  2238.     bool bUseLinearSmoothing;
  2239.  
  2240.     /** Maximum location correction distance for which other pawn positions on a client will be smoothly updated */
  2241.     float MaxSmoothNetUpdateDist;
  2242.  
  2243.     /** If the updated location is more than NoSmoothNetUpdateDist from the current pawn position on the client, pop it to the updated location.
  2244.     If it is between MaxSmoothNetUpdateDist and NoSmoothNetUpdateDist, pop to MaxSmoothNetUpdateDist away from the updated location */
  2245.     float NoSmoothNetUpdateDist;
  2246.  
  2247.     /** How long to take to smoothly interpolate from the old pawn position on the client to the corrected one sent by the server.  Must be >= 0.0
  2248.     This variable isn't used when bUseLinearSmoothing = true */
  2249.     float SmoothNetUpdateTime;
  2250.  
  2251.     /** How long to take to smoothly interpolate from the old pawn rotation on the client to the corrected one sent by the server.  Must be >= 0.0
  2252.     This variable isn't used when bUseLinearSmoothing = true */
  2253.     float SmoothNetUpdateRotationTime;
  2254.  
  2255.     // how long server will wait for client move update before setting position
  2256.     // @TODO: don't duplicate between server and client data (though it's used by both)
  2257.     float MaxResponseTime;
  2258.  
  2259.     /** Finds SavedMove index for given TimeStamp. Returns INDEX_NONE if not found (move has been already Acked or cleared). */
  2260.     int32 GetSavedMoveIndex(float TimeStamp) const;
  2261.  
  2262.     /** Ack a given move. This move will become LastAckedMove, SavedMoves will be adjusted to only contain unAcked moves. */
  2263.     void AckMove(int32 AckedMoveIndex);
  2264.  
  2265.     /** Allocate a new saved move. Subclasses should override this if they want to use a custom move class. */
  2266.     virtual FSavedMovePtr AllocateNewMove();
  2267.  
  2268.     /** Return a move to the free move pool. Assumes that 'Move' will no longer be referenced by anything but possibly the FreeMoves list. Clears PendingMove if 'Move' is PendingMove. */
  2269.     virtual void FreeMove(const FSavedMovePtr& Move);
  2270.  
  2271.     /** Tries to pull a pooled move off the free move list, otherwise allocates a new move. Returns NULL if the limit on saves moves is hit. */
  2272.     virtual FSavedMovePtr CreateSavedMove();
  2273.  
  2274.     /** Update CurentTimeStamp from passed in DeltaTime.
  2275.     It will measure the accuracy between passed in DeltaTime and how Server will calculate its DeltaTime.
  2276.     If inaccuracy is too high, it will reset CurrentTimeStamp to maintain a high level of accuracy.
  2277.     @return DeltaTime to use for Client's physics simulation prior to replicate move to server. */
  2278.     float UpdateTimeStampAndDeltaTime(float DeltaTime, ACharacter & CharacterOwner, class UCharacterMovementComponent & CharacterMovementComponent);
  2279. };
  2280.  
  2281.  
  2282. class ENGINE_API FNetworkPredictionData_Server_Character : public FNetworkPredictionData_Server
  2283. {
  2284. public:
  2285.  
  2286.     FNetworkPredictionData_Server_Character();
  2287.     virtual ~FNetworkPredictionData_Server_Character();
  2288.  
  2289.     FClientAdjustment PendingAdjustment;
  2290.  
  2291.     float CurrentClientTimeStamp;   // Timestamp from the Client of most recent ServerMove() processed for this player
  2292.     float LastUpdateTime;           // Last time server updated client with a move correction or confirmation
  2293.  
  2294.     // how long server will wait for client move update before setting position
  2295.     // @TODO: don't duplicate between server and client data (though it's used by both)
  2296.     float MaxResponseTime;
  2297.  
  2298.     uint32 bForceClientUpdate : 1;  // Force client update on the next ServerMoveHandleClientError() call.
  2299.  
  2300.     /** @return time delta to use for the current ServerMove() */
  2301.     float GetServerMoveDeltaTime(float TimeStamp) const;
  2302. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement