Space Plunder
Loading...
Searching...
No Matches
UALSCharacterMovementComponent Class Reference

#include <ALSCharacterMovementComponent.h>

Inheritance diagram for UALSCharacterMovementComponent:
IALSCharacterMovementInterface IALSGravityMovementInterface

Classes

class  FNetworkPredictionData_Client_My
 
class  FSavedMove_My
 

Protected Member Functions

virtual void MulticastEnableAlignGravityToBase ()
 
virtual void MulticastDisableAlignGravityToBase ()
 
virtual void MulticastSetGravityScale (const float NewGravityScale)
 
virtual void MulticastSetFixedGravityDirection (const FVector &NewFixedGravityDirection)
 
virtual void MulticastSetSplineTangentGravityDirection (AActor *NewGravityActor)
 
virtual void MulticastSetPointGravityDirection (const FVector &NewGravityPoint)
 
virtual void MulticastSetPointGravityDirectionFromActor (AActor *NewGravityActor)
 
virtual void MulticastSetLineGravityDirection (const FVector &NewGravityLineStart, const FVector &NewGravityLineEnd)
 
virtual void MulticastSetSegmentGravityDirection (const FVector &NewGravitySegmentStart, const FVector &NewGravitySegmentEnd)
 
virtual void MulticastSetSplineGravityDirection (AActor *NewGravityActor)
 
virtual void MulticastSetPlaneGravityDirection (const FVector &NewGravityPlaneBase, const FVector &NewGravityPlaneNormal)
 
virtual void MulticastSetSplinePlaneGravityDirection (AActor *NewGravityActor)
 
virtual void MulticastSetBoxGravityDirection (const FVector &NewGravityBoxOrigin, const FVector &NewGravityBoxExtent)
 
virtual void MulticastSetBoxGravityDirectionFromActor (AActor *NewGravityActor)
 
virtual void MulticastSetCollisionGravityDirection (AActor *NewGravityActor)
 
void GravityDirectionChanged (const EGravityDirectionMode OldGravityDirectionMode)
 
virtual bool GetShouldReplicateGravity () const
 

Protected Attributes

EGravityDirectionMode GravityDirectionMode
 
FVector GravityVectorA
 
FVector GravityVectorB
 
TObjectPtr< AActor > GravityActor
 
float OldGravityScale
 
uint32 bDirtyGravityDirection:1
 
uint32 bDisableGravityReplication:1
 

Private Member Functions

virtual void UpdateFromCompressedFlags (uint8 Flags) override
 
virtual class FNetworkPredictionData_Client * GetPredictionData_Client () const override
 
virtual void OnMovementUpdated (float DeltaTime, const FVector &OldLocation, const FVector &OldVelocity) override
 
virtual void PhysWalking (float deltaTime, int32 Iterations) override
 
virtual float GetMaxAcceleration () const override
 
virtual float GetMaxBrakingDeceleration () const override
 
float GetMappedSpeed () const
 
void SetMovementSettings (FALSMovementSettings NewMovementSettings)
 
void SetAllowedGait (EALSGait NewAllowedGait)
 
void Server_SetAllowedGait (EALSGait NewAllowedGait)
 
virtual void SetNewGravityScale (const float NewGravity) override
 
virtual void ResetGravityScale () override
 
virtual void SetFixedGravityDirection (const FVector &NewFixedGravityDirection) override
 
virtual void SetSplineTangentGravityDirection (AActor *NewGravityActor) override
 
virtual void SetPointGravityDirection (const FVector &NewGravityPoint) override
 
virtual void SetPointGravityDirectionFromActor (AActor *NewGravityActor) override
 
virtual void SetLineGravityDirection (const FVector &NewGravityLineStart, const FVector &NewGravityLineEnd) override
 
virtual void SetSegmentGravityDirection (const FVector &NewGravitySegmentStart, const FVector &NewGravitySegmentEnd) override
 
virtual void SetSplineGravityDirection (AActor *NewGravityActor) override
 
virtual void SetPlaneGravityDirection (const FVector &NewGravityPlaneBase, const FVector &NewGravityPlaneNormal) override
 
virtual void SetSplinePlaneGravityDirection (AActor *NewGravityActor) override
 
virtual void SetBoxGravityDirection (const FVector &NewGravityBoxOrigin, const FVector &NewGravityBoxExtent) override
 
virtual void SetBoxGravityDirectionFromActor (AActor *NewGravityActor) override
 
virtual void SetCollisionGravityDirection (AActor *NewGravityActor) override
 
virtual bool GetIsWalking () const override
 
virtual void LaunchCharacter (const FVector &LaunchVel) override
 
virtual FVector GetGravityDirection () const override
 
virtual void UpdateGravity ()
 
virtual void ReplicateGravityToClients ()
 
virtual void SetAlignGravityToBase (bool bNewAlignGravityToBase)
 

Private Attributes

uint8 bRequestMovementSettingsChange = 1
 
EALSGait AllowedGait = EALSGait::Walking
 
FALSMovementSettings CurrentMovementSettings
 
FOnGravityDirectionChanged OnGravityDirectionChanged
 
uint32 bAlignGravityToBase:1
 

Additional Inherited Members

Detailed Description

Authoritative networked Character Movement

Member Function Documentation

◆ GetGravityDirection()

FVector UALSCharacterMovementComponent::GetGravityDirection ( ) const
overrideprivatevirtual

Implements IALSGravityMovementInterface.

861{
862 switch (GravityDirectionMode)
863 {
865 // Gravity is in a fixed direction (GravityVectorA).
866 return GravityVectorA.GetSafeNormal();
867
869 // Gravity pulls towards a specific point (like a planet center).
870 if (GravityActor)
871 {
872 return (GravityActor->GetActorLocation() - GetOwner()->GetActorLocation()).GetSafeNormal();
873 }
874 return (GravityVectorA - GetOwner()->GetActorLocation()).GetSafeNormal();
875
878 // Gravity is along a line or segment between two points (GravityVectorA and GravityVectorB).
879 return (GravityVectorB - GravityVectorA).GetSafeNormal();
880
884 // Gravity follows the tangent of a spline (typically along a path).
885 if (const USplineComponent* Spline = Cast<USplineComponent>(GravityActor->GetComponentByClass(USplineComponent::StaticClass())))
886 {
887 FVector ClosestPoint = Spline->FindLocationClosestToWorldLocation(GetOwner()->GetActorLocation(), ESplineCoordinateSpace::World);
888 return Spline->FindTangentClosestToWorldLocation(ClosestPoint, ESplineCoordinateSpace::World).GetSafeNormal();
889 }
890 break;
891
893 // Gravity is along a plane normal (GravityVectorB is the normal).
894 return GravityVectorB.GetSafeNormal();
895
897 // Gravity is towards the center of a box.
898 return (GravityVectorA - GetOwner()->GetActorLocation()).GetSafeNormal();
899
901 // Gravity is derived from a collision (e.g., based on the normal of the collision surface).
902 if (GravityActor)
903 {
904 const UPrimitiveComponent* PrimitiveComponent = Cast<UPrimitiveComponent>(GravityActor->GetRootComponent());
905 if (PrimitiveComponent)
906 {
907 return PrimitiveComponent->GetComponentLocation().GetSafeNormal();
908 }
909 }
910 break;
911
912 default:
913 break;
914 }
915 // Fallback to world gravity (e.g., downwards) if no specific direction is set.
916 return FVector(0.0f, 0.0f, -1.0f);
917}
FVector GravityVectorB
Definition ALSCharacterMovementComponent.h:320
EGravityDirectionMode GravityDirectionMode
Definition ALSCharacterMovementComponent.h:312
FVector GravityVectorA
Definition ALSCharacterMovementComponent.h:316
TObjectPtr< AActor > GravityActor
Definition ALSCharacterMovementComponent.h:324

◆ GetIsWalking()

bool UALSCharacterMovementComponent::GetIsWalking ( ) const
overrideprivatevirtual

Returns true if the character is in the 'Walking' movement mode.

Implements IALSGravityMovementInterface.

847{
848 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
849 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
850 return IsWalking();
851}

◆ GetMappedSpeed()

float UALSCharacterMovementComponent::GetMappedSpeed ( ) const
private
227{
228 TRACE_CPUPROFILER_EVENT_SCOPE(UALSCharacterMovementComponent::GetMappedSpeed);
229 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
230
231 // Map the character's current speed to the configured movement speeds with a range of 0-3,
232 // with 0 = stopped, 1 = the Walk Speed, 2 = the Run Speed, and 3 = the Sprint Speed.
233 // This allows us to vary the movement speeds but still use the mapped range in calculations for consistent results
234
235 const float Speed = Velocity.Size2D();
236 const float LocWalkSpeed = CurrentMovementSettings.WalkSpeed;
237 const float LocRunSpeed = CurrentMovementSettings.RunSpeed;
238 const float LocSprintSpeed = CurrentMovementSettings.SprintSpeed;
239
240 if (Speed > LocRunSpeed)
241 {
242 return FMath::GetMappedRangeValueClamped<float, float>({LocRunSpeed, LocSprintSpeed}, {2.0f, 3.0f}, Speed);
243 }
244
245 if (Speed > LocWalkSpeed)
246 {
247 return FMath::GetMappedRangeValueClamped<float, float>({LocWalkSpeed, LocRunSpeed}, {1.0f, 2.0f}, Speed);
248 }
249
250 return FMath::GetMappedRangeValueClamped<float, float>({0.0f, LocWalkSpeed}, {0.0f, 1.0f}, Speed);
251}
float GetMappedSpeed() const
Definition ALSCharacterMovementComponent.cpp:226
FALSMovementSettings CurrentMovementSettings
Definition ALSCharacterMovementComponent.h:70
float SprintSpeed
Definition ALSCharacterStructLibrary.h:186
float RunSpeed
Definition ALSCharacterStructLibrary.h:183
float WalkSpeed
Definition ALSCharacterStructLibrary.h:180

◆ GetMaxAcceleration()

float UALSCharacterMovementComponent::GetMaxAcceleration ( ) const
overrideprivatevirtual
96{
97 TRACE_CPUPROFILER_EVENT_SCOPE(UALSCharacterMovementComponent::GetMaxAcceleration);
98 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
99
100 // Update the Acceleration using the Movement Curve.
101 // This allows for fine control over movement behavior at each speed.
102 if (!IsMovingOnGround() || !CurrentMovementSettings.MovementCurve)
103 {
104 return Super::GetMaxAcceleration();
105 }
106 return CurrentMovementSettings.MovementCurve->GetVectorValue(GetMappedSpeed()).X;
107}
virtual float GetMaxAcceleration() const override
Definition ALSCharacterMovementComponent.cpp:95
TObjectPtr< UCurveVector > MovementCurve
Definition ALSCharacterStructLibrary.h:192

◆ GetMaxBrakingDeceleration()

float UALSCharacterMovementComponent::GetMaxBrakingDeceleration ( ) const
overrideprivatevirtual
110{
112 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
113
114 // Update the Deceleration using the Movement Curve.
115 // This allows for fine control over movement behavior at each speed.
116 if (!IsMovingOnGround() || !CurrentMovementSettings.MovementCurve)
117 {
118 return Super::GetMaxBrakingDeceleration();
119 }
120 return CurrentMovementSettings.MovementCurve->GetVectorValue(GetMappedSpeed()).Y;
121}
virtual float GetMaxBrakingDeceleration() const override
Definition ALSCharacterMovementComponent.cpp:109

◆ GetPredictionData_Client()

class FNetworkPredictionData_Client * UALSCharacterMovementComponent::GetPredictionData_Client ( ) const
overrideprivatevirtual
134{
136 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
137
138 check(PawnOwner != nullptr);
139
140 if (!ClientPredictionData)
141 {
142 UALSCharacterMovementComponent* MutableThis = const_cast<UALSCharacterMovementComponent*>(this);
143
144 MutableThis->ClientPredictionData = new FNetworkPredictionData_Client_My(*this);
145 MutableThis->ClientPredictionData->MaxSmoothNetUpdateDist = 92.f;
146 MutableThis->ClientPredictionData->NoSmoothNetUpdateDist = 140.f;
147 }
148
149 return ClientPredictionData;
150}
Definition ALSCharacterMovementComponent.h:23
virtual class FNetworkPredictionData_Client * GetPredictionData_Client() const override
Definition ALSCharacterMovementComponent.cpp:133

◆ GetShouldReplicateGravity()

bool UALSCharacterMovementComponent::GetShouldReplicateGravity ( ) const
protectedvirtual

Asks if gravity data should be replicated from server to clients.

Returns
true if gravity data should be replicated
1092{
1093 return (!bDisableGravityReplication && CharacterOwner != nullptr &&
1094 CharacterOwner->HasAuthority() && GetNetMode() != ENetMode::NM_Standalone);
1095
1096}
uint32 bDisableGravityReplication
Definition ALSCharacterMovementComponent.h:338

◆ GravityDirectionChanged()

void UALSCharacterMovementComponent::GravityDirectionChanged ( const EGravityDirectionMode OldGravityDirectionMode)
protected

Called after GravityDirectionMode (or related data) has changed.

Parameters
OldGravityDirectionMode- previous value of GravityDirectionMode
831{
832 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
833 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
834 OnGravityDirectionChanged.Broadcast(OldGravityDirectionMode, GravityDirectionMode);
835
836 // Call owner delegate
837 // IALSCharacterInterface* Character = Cast<IALSCharacterInterface>(CharacterOwner);
838 // if (Character != nullptr)
839 // {
840 // Character->GravityDirectionChanged(OldGravityDirectionMode, GravityDirectionMode);
841 // }
842
843}
FOnGravityDirectionChanged OnGravityDirectionChanged
Definition ALSCharacterMovementComponent.h:89

◆ LaunchCharacter()

void UALSCharacterMovementComponent::LaunchCharacter ( const FVector & LaunchVel)
overrideprivatevirtual

Queue a pending launch with velocity LaunchVel.

Implements IALSGravityMovementInterface.

854{
855 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
856 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
857 Launch(LaunchVel);
858}

◆ MulticastDisableAlignGravityToBase()

virtual void UALSCharacterMovementComponent::MulticastDisableAlignGravityToBase ( )
protectedvirtual

Disables bAlignGravityToBase flag for clients.

◆ MulticastEnableAlignGravityToBase()

virtual void UALSCharacterMovementComponent::MulticastEnableAlignGravityToBase ( )
protectedvirtual

Enables bAlignGravityToBase flag for clients.

◆ MulticastSetBoxGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetBoxGravityDirection ( const FVector & NewGravityBoxOrigin,
const FVector & NewGravityBoxExtent )
protectedvirtual

Replicates a new axis-aligned box for gravity to clients.

Parameters
NewGravityBoxOrigin- origin of the box
NewGravityBoxExtent- extents of the box

◆ MulticastSetBoxGravityDirectionFromActor()

virtual void UALSCharacterMovementComponent::MulticastSetBoxGravityDirectionFromActor ( AActor * NewGravityActor)
protectedvirtual

Replicates a new axis-aligned box for gravity to clients.

Parameters
NewGravityActor- Actor that provides its collision bounding box as gravity target

◆ MulticastSetCollisionGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetCollisionGravityDirection ( AActor * NewGravityActor)
protectedvirtual

Replicates a new collision geometry for gravity to clients.

Parameters
NewGravityActor- Actor that owns the PrimitiveComponent that has collision geometry

◆ MulticastSetFixedGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetFixedGravityDirection ( const FVector & NewFixedGravityDirection)
protectedvirtual

Replicates a new fixed gravity direction to clients.

Parameters
NewFixedGravityDirection- new fixed gravity direction, assumes it is normalized

◆ MulticastSetGravityScale()

virtual void UALSCharacterMovementComponent::MulticastSetGravityScale ( const float NewGravityScale)
protectedvirtual

Replicates gravity scale factor to clients.

Parameters
NewGravityScale- new gravity scale factor

◆ MulticastSetLineGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetLineGravityDirection ( const FVector & NewGravityLineStart,
const FVector & NewGravityLineEnd )
protectedvirtual

Replicates a new infinite line for gravity to clients.

Parameters
NewGravityLineStart- a point that belongs to the infinite line
NewGravityLineEnd- another point that belongs to the infinite line

◆ MulticastSetPlaneGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetPlaneGravityDirection ( const FVector & NewGravityPlaneBase,
const FVector & NewGravityPlaneNormal )
protectedvirtual

Replicates a new infinite plane for gravity to clients.

Parameters
NewGravityPlaneBase- a point that belongs to the plane
NewGravityPlaneNormal- normal of the plane, assumes it is normalized

◆ MulticastSetPointGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetPointGravityDirection ( const FVector & NewGravityPoint)
protectedvirtual

Replicates a new gravity point to clients.

Parameters
NewGravityPoint- new point which gravity direction points to

◆ MulticastSetPointGravityDirectionFromActor()

virtual void UALSCharacterMovementComponent::MulticastSetPointGravityDirectionFromActor ( AActor * NewGravityActor)
protectedvirtual

Replicates a new gravity point to clients.

Parameters
NewGravityActor- Actor that provides its location as gravity point

◆ MulticastSetSegmentGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetSegmentGravityDirection ( const FVector & NewGravitySegmentStart,
const FVector & NewGravitySegmentEnd )
protectedvirtual

Replicates a new segment line for gravity to clients.

Parameters
NewGravitySegmentStart- start point of the segment line
NewGravitySegmentEnd- end point of the segment line

◆ MulticastSetSplineGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetSplineGravityDirection ( AActor * NewGravityActor)
protectedvirtual

Replicates a new spline for gravity to clients.

Parameters
NewGravityActor- Actor that provides a spline

◆ MulticastSetSplinePlaneGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetSplinePlaneGravityDirection ( AActor * NewGravityActor)
protectedvirtual

Replicates a new infinite plane determined by closest spline point for gravity to clients.

Parameters
NewGravityActor- Actor that provides a spline

◆ MulticastSetSplineTangentGravityDirection()

virtual void UALSCharacterMovementComponent::MulticastSetSplineTangentGravityDirection ( AActor * NewGravityActor)
protectedvirtual

Replicates a new spline gravity direction to clients.

Parameters
NewGravityActor- Actor that provides a spline

◆ OnMovementUpdated()

void UALSCharacterMovementComponent::OnMovementUpdated ( float DeltaTime,
const FVector & OldLocation,
const FVector & OldVelocity )
overrideprivatevirtual
49{
50 TRACE_CPUPROFILER_EVENT_SCOPE(UALSCharacterMovementComponent::OnMovementUpdated);
51 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
52
53 Super::OnMovementUpdated(DeltaTime, OldLocation, OldVelocity);
54
55
56 if (!CharacterOwner)
57 {
58 return;
59 }
60
61 // Set Movement Settings
63 {
64 const float UpdateMaxWalkSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait);
65 MaxWalkSpeed = UpdateMaxWalkSpeed;
66 MaxWalkSpeedCrouched = UpdateMaxWalkSpeed;
67
69 }
70
71
72 //~ Gravity Functions //
75 {
77 }
78
79}
virtual void ReplicateGravityToClients()
Definition ALSCharacterMovementComponent.cpp:975
EALSGait AllowedGait
Definition ALSCharacterMovementComponent.h:67
uint8 bRequestMovementSettingsChange
Definition ALSCharacterMovementComponent.h:64
virtual void UpdateGravity()
Definition ALSCharacterMovementComponent.cpp:919
virtual bool GetShouldReplicateGravity() const
Definition ALSCharacterMovementComponent.cpp:1091
virtual void OnMovementUpdated(float DeltaTime, const FVector &OldLocation, const FVector &OldVelocity) override
Definition ALSCharacterMovementComponent.cpp:47
float GetSpeedForGait(const EALSGait Gait) const
Definition ALSCharacterStructLibrary.h:197

◆ PhysWalking()

void UALSCharacterMovementComponent::PhysWalking ( float deltaTime,
int32 Iterations )
overrideprivatevirtual
82{
83 TRACE_CPUPROFILER_EVENT_SCOPE(UALSCharacterMovementComponent::PhysWalking);
84 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
85
87 {
88 // Update the Ground Friction using the Movement Curve.
89 // This allows for fine control over movement behavior at each speed.
90 GroundFriction = CurrentMovementSettings.MovementCurve->GetVectorValue(GetMappedSpeed()).Z;
91 }
92 Super::PhysWalking(deltaTime, Iterations);
93}
virtual void PhysWalking(float deltaTime, int32 Iterations) override
Definition ALSCharacterMovementComponent.cpp:81

◆ ReplicateGravityToClients()

void UALSCharacterMovementComponent::ReplicateGravityToClients ( )
privatevirtual

Sends gravity data from server to clients.

976{
978 {
979 // Replicate gravity direction to clients
980 switch (GravityDirectionMode)
981 {
983 {
985 break;
986 }
987
989 {
991 break;
992 }
993
995 {
997 break;
998 }
999
1001 {
1003 break;
1004 }
1005
1007 {
1009 break;
1010 }
1011
1013 {
1015 break;
1016 }
1017
1019 {
1021 break;
1022 }
1023
1025 {
1027 break;
1028 }
1029
1031 {
1033 break;
1034 }
1035
1037 {
1039 break;
1040 }
1041 }
1042
1043 bDirtyGravityDirection = false;
1044 }
1045 if (OldGravityScale != GravityScale)
1046 {
1047 // Replicate gravity scale to clients
1048 MulticastSetGravityScale(GravityScale);
1049 OldGravityScale = GravityScale;
1050 }
1051}
virtual void MulticastSetSplineTangentGravityDirection(AActor *NewGravityActor)
virtual void MulticastSetSegmentGravityDirection(const FVector &NewGravitySegmentStart, const FVector &NewGravitySegmentEnd)
virtual void MulticastSetBoxGravityDirection(const FVector &NewGravityBoxOrigin, const FVector &NewGravityBoxExtent)
virtual void MulticastSetSplinePlaneGravityDirection(AActor *NewGravityActor)
virtual void MulticastSetLineGravityDirection(const FVector &NewGravityLineStart, const FVector &NewGravityLineEnd)
virtual void MulticastSetCollisionGravityDirection(AActor *NewGravityActor)
virtual void MulticastSetPlaneGravityDirection(const FVector &NewGravityPlaneBase, const FVector &NewGravityPlaneNormal)
virtual void MulticastSetPointGravityDirection(const FVector &NewGravityPoint)
virtual void MulticastSetGravityScale(const float NewGravityScale)
virtual void MulticastSetSplineGravityDirection(AActor *NewGravityActor)
virtual void MulticastSetFixedGravityDirection(const FVector &NewFixedGravityDirection)
float OldGravityScale
Definition ALSCharacterMovementComponent.h:330
uint32 bDirtyGravityDirection
Definition ALSCharacterMovementComponent.h:334

◆ ResetGravityScale()

void UALSCharacterMovementComponent::ResetGravityScale ( )
overrideprivatevirtual

Implements IALSGravityMovementInterface.

301{
302 GravityScale = OldGravityScale;
303}

◆ Server_SetAllowedGait()

void UALSCharacterMovementComponent::Server_SetAllowedGait ( EALSGait NewAllowedGait)
private

◆ SetAlignGravityToBase()

void UALSCharacterMovementComponent::SetAlignGravityToBase ( bool bNewAlignGravityToBase)
privatevirtual

Sets a new state for bAlignGravityToBase flag.

Parameters
bNewAlignGravityToBase- new value for bAlignGravityToBase flag
1054{
1055 if (bAlignGravityToBase == bNewAlignGravityToBase)
1056 {
1057 return;
1058 }
1059
1060 bAlignGravityToBase = bNewAlignGravityToBase;
1061
1063 {
1065 {
1067 }
1068 else
1069 {
1071 }
1072 }
1073
1074}
virtual void MulticastEnableAlignGravityToBase()
uint32 bAlignGravityToBase
Definition ALSCharacterMovementComponent.h:196
virtual void MulticastDisableAlignGravityToBase()

◆ SetAllowedGait()

void UALSCharacterMovementComponent::SetAllowedGait ( EALSGait NewAllowedGait)
private
264{
265 TRACE_CPUPROFILER_EVENT_SCOPE(UALSCharacterMovementComponent::SetAllowedGait);
266 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
267
268 if (AllowedGait != NewAllowedGait)
269 {
270 if (PawnOwner->IsLocallyControlled())
271 {
272 AllowedGait = NewAllowedGait;
273 if (GetCharacterOwner()->GetLocalRole() == ROLE_AutonomousProxy)
274 {
275 Server_SetAllowedGait(NewAllowedGait);
276 }
278 return;
279 }
280 if (!PawnOwner->HasAuthority())
281 {
282 const float UpdateMaxWalkSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait);
283 MaxWalkSpeed = UpdateMaxWalkSpeed;
284 MaxWalkSpeedCrouched = UpdateMaxWalkSpeed;
285 }
286 }
287}
void Server_SetAllowedGait(EALSGait NewAllowedGait)
void SetAllowedGait(EALSGait NewAllowedGait)
Definition ALSCharacterMovementComponent.cpp:263

◆ SetBoxGravityDirection()

void UALSCharacterMovementComponent::SetBoxGravityDirection ( const FVector & NewGravityBoxOrigin,
const FVector & NewGravityBoxExtent )
overrideprivatevirtual

Sets a new axis-aligned box which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityBoxOrigin- origin of the box
NewGravityBoxExtent- extents of the box

Implements IALSGravityMovementInterface.

699{
700 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
701 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
703 GravityVectorA == NewGravityBoxOrigin && GravityVectorB == NewGravityBoxExtent)
704 {
705 return;
706 }
707
708 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
709
712 GravityVectorA = NewGravityBoxOrigin;
713 GravityVectorB = NewGravityBoxExtent;
714 GravityActor = nullptr;
715
716 GravityDirectionChanged(OldGravityDirectionMode);
717
718
719}
EGravityDirectionMode
Definition ALSExtraData.h:14
void GravityDirectionChanged(const EGravityDirectionMode OldGravityDirectionMode)
Definition ALSCharacterMovementComponent.cpp:830

◆ SetBoxGravityDirectionFromActor()

void UALSCharacterMovementComponent::SetBoxGravityDirectionFromActor ( AActor * NewGravityActor)
overrideprivatevirtual

Sets a new axis-aligned box which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityActor- Actor that provides its collision bounding box as gravity target

Implements IALSGravityMovementInterface.

747{
748 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
749 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
751 {
752 return;
753 }
754
755 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
756
759 GravityActor = NewGravityActor;
760
761 GravityDirectionChanged(OldGravityDirectionMode);
762
763
764}

◆ SetCollisionGravityDirection()

void UALSCharacterMovementComponent::SetCollisionGravityDirection ( AActor * NewGravityActor)
overrideprivatevirtual

Sets a new collision geometry which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityActor- Actor that owns the PrimitiveComponent that has collision geometry

Implements IALSGravityMovementInterface.

786{
787 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
788 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
789 if (NewGravityActor == nullptr ||
791 GravityActor == NewGravityActor))
792 {
793 return;
794 }
795
796 const UPrimitiveComponent* Primitive = Cast<UPrimitiveComponent>(NewGravityActor->GetRootComponent());
797 if (Primitive != nullptr)
798 {
799 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
800
803 GravityActor = NewGravityActor;
804
805 GravityDirectionChanged(OldGravityDirectionMode);
806 }
807
808
809}

◆ SetFixedGravityDirection()

void UALSCharacterMovementComponent::SetFixedGravityDirection ( const FVector & NewFixedGravityDirection)
overrideprivatevirtual

Sets a new fixed gravity direction.

Note
It can be influenced by GravityScale
Parameters
NewFixedGravityDirection- new fixed gravity direction, assumes it is normalized

Implements IALSGravityMovementInterface.

306{
307 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
308 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
309 if (NewFixedGravityDirection.IsZero() ||
311 GravityVectorA == NewFixedGravityDirection))
312 {
313 return;
314 }
315
316 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
317
320 GravityVectorA = NewFixedGravityDirection;
321 GravityDirectionChanged(OldGravityDirectionMode);
322}

◆ SetLineGravityDirection()

void UALSCharacterMovementComponent::SetLineGravityDirection ( const FVector & NewGravityLineStart,
const FVector & NewGravityLineEnd )
overrideprivatevirtual

Sets a new infinite line which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityLineStart- a point that belongs to the infinite line
NewGravityLineEnd- another point that belongs to the infinite line

Implements IALSGravityMovementInterface.

474{
475 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
476 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
477 if (NewGravityLineStart == NewGravityLineEnd ||
479 GravityVectorA == NewGravityLineStart && GravityVectorB == NewGravityLineEnd))
480 {
481 return;
482 }
483
484 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
485
488 GravityVectorA = NewGravityLineStart;
489 GravityVectorB = NewGravityLineEnd;
490
491 GravityDirectionChanged(OldGravityDirectionMode);
492
493}

◆ SetMovementSettings()

void UALSCharacterMovementComponent::SetMovementSettings ( FALSMovementSettings NewMovementSettings)
private
254{
255 TRACE_CPUPROFILER_EVENT_SCOPE(UALSCharacterMovementComponent::SetMovementSettings);
256 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
257
258 // Set the current movement settings from the owner
259 CurrentMovementSettings = NewMovementSettings;
261}
void SetMovementSettings(FALSMovementSettings NewMovementSettings)
Definition ALSCharacterMovementComponent.cpp:253

◆ SetNewGravityScale()

void UALSCharacterMovementComponent::SetNewGravityScale ( const float NewGravity)
overrideprivatevirtual

Implements IALSGravityMovementInterface.

295{
296 OldGravityScale = GravityScale;
297 GravityScale = NewGravity;
298}

◆ SetPlaneGravityDirection()

void UALSCharacterMovementComponent::SetPlaneGravityDirection ( const FVector & NewGravityPlaneBase,
const FVector & NewGravityPlaneNormal )
overrideprivatevirtual

Sets a new infinite plane which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityPlaneBase- a point that belongs to the plane
NewGravityPlaneNormal- normal of the plane, assumes it is normalized

Implements IALSGravityMovementInterface.

605{
606 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
607 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
608 if (NewGravityPlaneNormal.IsZero() ||
610 GravityVectorA == NewGravityPlaneBase && GravityVectorB == NewGravityPlaneNormal))
611 {
612 return;
613 }
614
615 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
616
619 GravityVectorA = NewGravityPlaneBase;
620 GravityVectorB = NewGravityPlaneNormal;
621
622 GravityDirectionChanged(OldGravityDirectionMode);
623
624
625}

◆ SetPointGravityDirection()

void UALSCharacterMovementComponent::SetPointGravityDirection ( const FVector & NewGravityPoint)
overrideprivatevirtual

Sets a new point which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityPoint- new point which gravity direction points to

Implements IALSGravityMovementInterface.

390{
391 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
392 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
394 GravityVectorA == NewGravityPoint)
395 {
396 return;
397 }
398
399 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
400
403 GravityVectorA = NewGravityPoint;
404 GravityActor = nullptr;
405
406 GravityDirectionChanged(OldGravityDirectionMode);
407
408}

◆ SetPointGravityDirectionFromActor()

void UALSCharacterMovementComponent::SetPointGravityDirectionFromActor ( AActor * NewGravityActor)
overrideprivatevirtual

Sets a new point which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityActor- Actor that provides its location as gravity point

Implements IALSGravityMovementInterface.

431{
432 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
433 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
435 GravityActor == NewGravityActor)
436 {
437 return;
438 }
439
440 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
441
444 GravityActor = NewGravityActor;
445
446 GravityDirectionChanged(OldGravityDirectionMode);
447
448}

◆ SetSegmentGravityDirection()

void UALSCharacterMovementComponent::SetSegmentGravityDirection ( const FVector & NewGravitySegmentStart,
const FVector & NewGravitySegmentEnd )
overrideprivatevirtual

Sets a new segment line which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravitySegmentStart- start point of the segment line
NewGravitySegmentEnd- end point of the segment line

Implements IALSGravityMovementInterface.

519{
520 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
521 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
522 if (NewGravitySegmentStart == NewGravitySegmentEnd ||
524 GravityVectorA == NewGravitySegmentStart && GravityVectorB == NewGravitySegmentEnd))
525 {
526 return;
527 }
528
529 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
530
533 GravityVectorA = NewGravitySegmentStart;
534 GravityVectorB = NewGravitySegmentEnd;
535
536 GravityDirectionChanged(OldGravityDirectionMode);
537
538
539}

◆ SetSplineGravityDirection()

void UALSCharacterMovementComponent::SetSplineGravityDirection ( AActor * NewGravityActor)
overrideprivatevirtual

Sets a new spline which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityActor- Actor that provides a spline

Implements IALSGravityMovementInterface.

564{
565 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
566 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
567 if (NewGravityActor == nullptr ||
569 GravityActor == NewGravityActor))
570 {
571 return;
572 }
573
574 const USplineComponent* Spline = Cast<USplineComponent>(
575 NewGravityActor->GetComponentByClass(USplineComponent::StaticClass()));
576 if (Spline != nullptr)
577 {
578 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
579
582 GravityActor = NewGravityActor;
583
584 GravityDirectionChanged(OldGravityDirectionMode);
585 }
586}

◆ SetSplinePlaneGravityDirection()

void UALSCharacterMovementComponent::SetSplinePlaneGravityDirection ( AActor * NewGravityActor)
overrideprivatevirtual

Sets a new infinite plane determined by closest spline point and spline up vector which gravity direction points to.

Note
It can be influenced by GravityScale
Parameters
NewGravityActor- Actor that provides a spline

Implements IALSGravityMovementInterface.

650{
651 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
652 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
653 if (NewGravityActor == nullptr ||
655 GravityActor == NewGravityActor))
656 {
657 return;
658 }
659
660 const USplineComponent* Spline = Cast<USplineComponent>(
661 NewGravityActor->GetComponentByClass(USplineComponent::StaticClass()));
662 if (Spline != nullptr)
663 {
664 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
665
668 GravityActor = NewGravityActor;
669
670 GravityDirectionChanged(OldGravityDirectionMode);
671 }
672
673
674}

◆ SetSplineTangentGravityDirection()

void UALSCharacterMovementComponent::SetSplineTangentGravityDirection ( AActor * NewGravityActor)
overrideprivatevirtual

Sets a new gravity direction determined by closest spline tangent.

Note
It can be influenced by GravityScale
Parameters
NewGravityActor- Actor that provides a spline

Implements IALSGravityMovementInterface.

345{
346 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
347 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement_Gravity);
348 if (NewGravityActor == nullptr ||
350 GravityActor == NewGravityActor))
351 {
352 return;
353 }
354
355 const USplineComponent* Spline = Cast<USplineComponent>(
356 NewGravityActor->GetComponentByClass(USplineComponent::StaticClass()));
357 if (Spline != nullptr)
358 {
359 const EGravityDirectionMode OldGravityDirectionMode = GravityDirectionMode;
360
363 GravityActor = NewGravityActor;
364
365 GravityDirectionChanged(OldGravityDirectionMode);
366 }
367
368}

◆ UpdateFromCompressedFlags()

void UALSCharacterMovementComponent::UpdateFromCompressedFlags ( uint8 Flags)
overrideprivatevirtual
124{
126 SCOPE_CYCLE_COUNTER(STATGROUP_ALS_Movement);
127
128 Super::UpdateFromCompressedFlags(Flags);
129
130 bRequestMovementSettingsChange = (Flags & FSavedMove_Character::FLAG_Custom_0) != 0;
131}
virtual void UpdateFromCompressedFlags(uint8 Flags) override
Definition ALSCharacterMovementComponent.cpp:123

◆ UpdateGravity()

void UALSCharacterMovementComponent::UpdateGravity ( )
privatevirtual

Update values related to gravity.

920{
921 if (!bAlignGravityToBase || !IsMovingOnGround())
922 {
923 return;
924 }
925
926 switch (GravityDirectionMode)
927 {
929 {
930 if (!CurrentFloor.HitResult.ImpactNormal.IsZero())
931 {
932 // Set the fixed gravity direction to reversed floor normal vector
933 SetFixedGravityDirection(CurrentFloor.HitResult.ImpactNormal * -1.0f);
934 }
935
936 break;
937 }
938
940 {
941 if (CurrentFloor.HitResult.GetActor() != nullptr)
942 {
943 // Set the point gravity direction from base
944 SetPointGravityDirectionFromActor(CurrentFloor.HitResult.GetActor());
945 }
946
947 break;
948 }
949
951 {
952 if (CurrentFloor.HitResult.GetActor() != nullptr)
953 {
954 // Set the box gravity direction from base
955 SetBoxGravityDirectionFromActor(CurrentFloor.HitResult.GetActor());
956 }
957
958 break;
959 }
961 default:
962 {
963 if (CurrentFloor.HitResult.GetActor() != nullptr)
964 {
965 // Set the collision gravity direction from base
966 SetCollisionGravityDirection(CurrentFloor.HitResult.GetActor());
967 }
968
969 break;
970 }
971 }
972
973}
virtual void SetCollisionGravityDirection(AActor *NewGravityActor) override
Definition ALSCharacterMovementComponent.cpp:785
virtual void SetPointGravityDirectionFromActor(AActor *NewGravityActor) override
Definition ALSCharacterMovementComponent.cpp:430
virtual void SetFixedGravityDirection(const FVector &NewFixedGravityDirection) override
Definition ALSCharacterMovementComponent.cpp:305
virtual void SetBoxGravityDirectionFromActor(AActor *NewGravityActor) override
Definition ALSCharacterMovementComponent.cpp:746

Member Data Documentation

◆ AllowedGait

EALSGait UALSCharacterMovementComponent::AllowedGait = EALSGait::Walking
private

◆ bAlignGravityToBase

uint32 UALSCharacterMovementComponent::bAlignGravityToBase
private

If true and a floor is found, rotate gravity direction and align it to floor base.

Note
For "Fixed" gravity mode, gravity direction is set to reverse floor normal vector
For "Point" gravity mode, gravity direction points to base's location
For "Box" gravity mode, gravity direction points to base's bounding box
For "Collision" gravity mode, gravity direction points to base's collision geometry

◆ bDirtyGravityDirection

uint32 UALSCharacterMovementComponent::bDirtyGravityDirection
protected

If true, gravity direction changed and needs to be replicated.

◆ bDisableGravityReplication

uint32 UALSCharacterMovementComponent::bDisableGravityReplication
protected

If true, gravity data isn't replicated from server to clients.

◆ bRequestMovementSettingsChange

uint8 UALSCharacterMovementComponent::bRequestMovementSettingsChange = 1
private

◆ CurrentMovementSettings

FALSMovementSettings UALSCharacterMovementComponent::CurrentMovementSettings
private

◆ GravityActor

TObjectPtr<AActor> UALSCharacterMovementComponent::GravityActor
protected

Optional Actor that determines direction of gravity.

◆ GravityDirectionMode

EGravityDirectionMode UALSCharacterMovementComponent::GravityDirectionMode
protected

Mode that determines direction of gravity.

◆ GravityVectorA

FVector UALSCharacterMovementComponent::GravityVectorA
protected

Stores information that determines direction of gravity.

◆ GravityVectorB

FVector UALSCharacterMovementComponent::GravityVectorB
protected

Stores additional information that determines direction of gravity.

◆ OldGravityScale

float UALSCharacterMovementComponent::OldGravityScale
protected

Stores last known value of GravityScale.

See also
GravityScale

◆ OnGravityDirectionChanged

FOnGravityDirectionChanged UALSCharacterMovementComponent::OnGravityDirectionChanged
private

The documentation for this class was generated from the following files: