UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CharacterGroundConstraint.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
8
9namespace Chaos
10{
19 {
20 public:
22 friend class FCharacterGroundConstraintProxy; // For setting the output data
23
25 virtual ~FCharacterGroundConstraint() override {}
26
27 // The constraint requires a character body, which is fixed, but the ground body is
28 // optional and can be changed dynamically using SetGroundParticleProxy
30
32 // Particle proxy
33
35 {
36 return CharacterProxy.Read().ParticleProxy;
37 }
38
40 {
41 return GroundProxy.Read().ParticleProxy;
42 }
43
45 {
46 GroundProxy.Modify(/*bInvalidate=*/true, DirtyFlags, Proxy, [InGroundProxy](FParticleProxyProperty& Data)
47 {
48 Data.ParticleProxy = InGroundProxy;
49 });
50 if (InGroundProxy)
51 {
52 WakeGroundBody();
53 }
54 }
55
57 // Settings accessors
58
62 {
63 FVec3 Tmp = Normal;
64 FReal SizeSq = Tmp.SizeSquared();
66 {
67 Tmp *= FMath::InvSqrt(SizeSq);
68 }
69 ConstraintData.Modify(true, DirtyFlags, Proxy, [&Tmp](FCharacterGroundConstraintDynamicData& Data) {
70 Data.GroundNormal = Tmp;
71 });
72 }
73 FVec3 GetGroundNormal() const { return ConstraintData.Read().GroundNormal; }
74
78 {
79 FVec3 Tmp = Axis;
80 FReal SizeSq = Tmp.SizeSquared();
82 {
83 Tmp *= FMath::InvSqrt(SizeSq);
84 }
86 Data.VerticalAxis = Tmp;
87 });
88 }
89 FVec3 GetVerticalAxis() const { return ConstraintSettings.Read().VerticalAxis; }
90
96 {
97 ConstraintData.Modify(true, DirtyFlags, Proxy, [&Value](FCharacterGroundConstraintDynamicData& Data) {
98 Data.GroundDistance = Value > FReal(0.0) ? Value : FReal(0.0);
99 });
100 WakeCharacterBody();
101 }
102 FReal GetGroundDistance() const { return ConstraintData.Read().GroundDistance; }
103
109 {
111 Data.TargetHeight = Value > FReal(0.0) ? Value : FReal(0.0);
112 });
113 }
114 FReal GetTargetHeight() const { return ConstraintSettings.Read().TargetHeight; }
115
122 {
124 Data.DampingFactor = Value > FReal(0.0) ? Value : FReal(0.0);
125 });
126 }
127 FReal GetDampingFactor() const { return ConstraintSettings.Read().DampingFactor; }
128
134 {
136 Data.MotionTargetMassBias = FMath::Clamp(Value, 0.0, 1.0);
137 });
138 }
139 FReal GetMotionTargetMassBias() const { return ConstraintSettings.Read().MotionTargetMassBias; }
140
146 {
148 Data.RadialForceMotionTargetScaling = FMath::Clamp(Value, 0.0, 1.0);
149 });
150 }
151 FReal GetRadialForceMotionTargetScaling() const { return ConstraintSettings.Read().RadialForceMotionTargetScaling; }
152
160 {
162 Data.AssumedOnGroundHeight = Value > FReal(0.0) ? Value : FReal(0.0);
163 });
164 }
165 FReal GetAssumedOnGroundHeight() const { return ConstraintSettings.Read().AssumedOnGroundHeight; }
166
172 {
175 Data.CosMaxWalkableSlopeAngle = FMath::Cos(Angle);
176 });
177 }
178 FReal GetMaxWalkableSlopeAngle() const { return FMath::Acos(ConstraintSettings.Read().CosMaxWalkableSlopeAngle); }
179
181 {
183 FReal CosAngle = FMath::Clamp(Value, -1.0, 1.0);
184 Data.CosMaxWalkableSlopeAngle = CosAngle;
185 });
186 }
187 FReal GetCosMaxWalkableSlopeAngle() const { return ConstraintSettings.Read().CosMaxWalkableSlopeAngle; }
188
199 {
200 ConstraintData.Modify(true, DirtyFlags, Proxy, [&Value](FCharacterGroundConstraintDynamicData& Data) {
201 Data.TargetDeltaPosition = Value;
202 });
203 WakeCharacterBody();
204 }
205 FVec3 GetTargetDeltaPosition() const { return ConstraintData.Read().TargetDeltaPosition; }
206
216 {
217 ConstraintData.Modify(true, DirtyFlags, Proxy, [&Value](FCharacterGroundConstraintDynamicData& Data) {
218 Data.TargetDeltaFacing = Value;
219 });
220 WakeCharacterBody();
221 }
222 FReal GetTargetDeltaFacing() const { return ConstraintData.Read().TargetDeltaFacing; }
223
226 void SetMotionTarget(const FVector& TargetDeltaPosition, const FReal& TargetDeltaFacing)
227 {
228 ConstraintData.Modify(true, DirtyFlags, Proxy, [&TargetDeltaPosition, &TargetDeltaFacing](FCharacterGroundConstraintDynamicData& Data) {
229 Data.TargetDeltaPosition = TargetDeltaPosition;
230 Data.TargetDeltaFacing = TargetDeltaFacing;
231 });
232 WakeCharacterBody();
233 }
234
239 {
241 Data.RadialForceLimit = Value > FReal(0.0) ? Value : FReal(0.0);
242 });
243 }
244 FReal GetRadialForceLimit() const { return ConstraintSettings.Read().RadialForceLimit; }
245
250 {
252 Data.FrictionForceLimit = Value > FReal(0.0) ? Value : FReal(0.0);
253 });
254 }
255 FReal GetFrictionForceLimit() const { return ConstraintSettings.Read().FrictionForceLimit; }
256
261 {
263 Data.TwistTorqueLimit = Value > FReal(0.0) ? Value : FReal(0.0);
264 });
265 }
266 FReal GetTwistTorqueLimit() const { return ConstraintSettings.Read().TwistTorqueLimit; }
267
271 {
273 Data.SwingTorqueLimit = Value > FReal(0.0) ? Value : FReal(0.0);
274 });
275 }
276 FReal GetSwingTorqueLimit() const { return ConstraintSettings.Read().SwingTorqueLimit; }
277
278 void SetUserData(void* Value)
279 {
281 Data.UserData = Value;
282 });
283 }
284 void* GetUserData() const { return ConstraintSettings.Read().UserData; }
285
292 {
294 Data.MaxCharacterGroundMassRatio = Value;
295 });
296 }
297 FReal GetMaxCharacterGroundMassRatio() const { return ConstraintSettings.Read().MaxCharacterGroundMassRatio; }
298
300 // Output
301
302 // Get the force applied by the solver due to this constraint. Units are ML/T^2
303 FVector GetSolverAppliedForce() const { return SolverAppliedForce; }
304
305 // Get the torque applied by the solver due to this constraint. Units are ML^2/T^2
306 FVector GetSolverAppliedTorque() const { return SolverAppliedTorque; }
307
308 private:
309 void WakeCharacterBody()
310 {
311 if (FSingleParticlePhysicsProxy* Character = CharacterProxy.Read().ParticleProxy)
312 {
313 FRigidBodyHandle_External& Body = Character->GetGameThreadAPI();
314 if (Body.ObjectState() == EObjectStateType::Sleeping)
315 {
316 Body.SetObjectState(EObjectStateType::Dynamic);
317 }
318 }
319 }
320
321 void WakeGroundBody()
322 {
323 if (FSingleParticlePhysicsProxy* Ground = GroundProxy.Read().ParticleProxy)
324 {
325 FRigidBodyHandle_External& Body = Ground->GetGameThreadAPI();
326 if (Body.ObjectState() == EObjectStateType::Sleeping)
327 {
328 Body.SetObjectState(EObjectStateType::Dynamic);
329 }
330 }
331 }
332
334 // FConstraintBase implementation
335 CHAOS_API virtual void SyncRemoteDataImp(FDirtyPropertiesManager& Manager, int32 DataIdx, FDirtyChaosProperties& RemoteData) override;
336
341
342 friend class FCharacterGroundConstraintProxy; // for setting the force and torque from the physics thread data
343 FVector SolverAppliedForce;
344 FVector SolverAppliedTorque;
345 };
346
347} // namespace Chaos
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
#define UE_HALF_PI
Definition UnrealMathUtility.h:151
Definition ChaosConstraintSettings.h:16
Definition CharacterGroundConstraintSettings.h:32
Definition CharacterGroundConstraintProxy.h:18
Definition CharacterGroundConstraintSettings.h:9
Definition CharacterGroundConstraint.h:19
void SetGroundNormal(const FVec3 &Normal)
Definition CharacterGroundConstraint.h:61
FReal GetTargetHeight() const
Definition CharacterGroundConstraint.h:114
void SetCosMaxWalkableSlopeAngle(const FReal &Value)
Definition CharacterGroundConstraint.h:180
void SetRadialForceMotionTargetScaling(const FReal &Value)
Definition CharacterGroundConstraint.h:145
void SetTargetDeltaFacing(const FReal &Value)
Definition CharacterGroundConstraint.h:215
void * GetUserData() const
Definition CharacterGroundConstraint.h:284
void SetSwingTorqueLimit(const FReal &Value)
Definition CharacterGroundConstraint.h:270
void SetMaxWalkableSlopeAngle(const FReal &Value)
Definition CharacterGroundConstraint.h:171
FSingleParticlePhysicsProxy * GetCharacterParticleProxy() const
Definition CharacterGroundConstraint.h:34
FReal GetTargetDeltaFacing() const
Definition CharacterGroundConstraint.h:222
void SetMotionTarget(const FVector &TargetDeltaPosition, const FReal &TargetDeltaFacing)
Definition CharacterGroundConstraint.h:226
FReal GetAssumedOnGroundHeight() const
Definition CharacterGroundConstraint.h:165
FVector GetSolverAppliedTorque() const
Definition CharacterGroundConstraint.h:306
FReal GetRadialForceLimit() const
Definition CharacterGroundConstraint.h:244
FVec3 GetGroundNormal() const
Definition CharacterGroundConstraint.h:73
void SetUserData(void *Value)
Definition CharacterGroundConstraint.h:278
void SetGroundParticleProxy(FSingleParticlePhysicsProxy *InGroundProxy)
Definition CharacterGroundConstraint.h:44
FReal GetMaxWalkableSlopeAngle() const
Definition CharacterGroundConstraint.h:178
FReal GetGroundDistance() const
Definition CharacterGroundConstraint.h:102
void SetRadialForceLimit(const FReal &Value)
Definition CharacterGroundConstraint.h:238
void SetDampingFactor(const FReal &Value)
Definition CharacterGroundConstraint.h:121
friend class FCharacterGroundConstraintProxy
Definition CharacterGroundConstraint.h:22
FReal GetCosMaxWalkableSlopeAngle() const
Definition CharacterGroundConstraint.h:187
FReal GetFrictionForceLimit() const
Definition CharacterGroundConstraint.h:255
FSingleParticlePhysicsProxy * GetGroundParticleProxy() const
Definition CharacterGroundConstraint.h:39
void SetGroundDistance(const FReal &Value)
Definition CharacterGroundConstraint.h:95
FReal GetMaxCharacterGroundMassRatio() const
Definition CharacterGroundConstraint.h:297
FVec3 GetVerticalAxis() const
Definition CharacterGroundConstraint.h:89
FVector GetSolverAppliedForce() const
Definition CharacterGroundConstraint.h:303
void SetMotionTargetMassBias(const FReal &Value)
Definition CharacterGroundConstraint.h:133
void SetTargetHeight(const FReal &Value)
Definition CharacterGroundConstraint.h:108
void SetFrictionForceLimit(const FReal &Value)
Definition CharacterGroundConstraint.h:249
void SetTargetDeltaPosition(const FVec3 &Value)
Definition CharacterGroundConstraint.h:198
FVec3 GetTargetDeltaPosition() const
Definition CharacterGroundConstraint.h:205
FReal GetDampingFactor() const
Definition CharacterGroundConstraint.h:127
void SetVerticalAxis(const FVec3 &Axis)
Definition CharacterGroundConstraint.h:77
FReal GetTwistTorqueLimit() const
Definition CharacterGroundConstraint.h:266
FReal GetMotionTargetMassBias() const
Definition CharacterGroundConstraint.h:139
void SetAssumedOnGroundHeight(const FReal &Value)
Definition CharacterGroundConstraint.h:159
void SetMaxCharacterGroundMassRatio(const FReal &Value)
Definition CharacterGroundConstraint.h:291
CHAOS_API FCharacterGroundConstraint()
Definition CharacterGroundConstraint.cpp:7
void SetTwistTorqueLimit(const FReal &Value)
Definition CharacterGroundConstraint.h:260
virtual ~FCharacterGroundConstraint() override
Definition CharacterGroundConstraint.h:25
FReal GetSwingTorqueLimit() const
Definition CharacterGroundConstraint.h:276
FReal GetRadialForceMotionTargetScaling() const
Definition CharacterGroundConstraint.h:151
Definition PBDConstraintBaseData.h:36
class IPhysicsProxyBase * Proxy
Definition PBDConstraintBaseData.h:69
FDirtyChaosPropertyFlags DirtyFlags
Definition PBDConstraintBaseData.h:70
Definition SingleParticlePhysicsProxy.h:1154
Definition SingleParticlePhysicsProxy.h:58
Definition SkeletalMeshComponent.h:307
FRealDouble FReal
Definition Real.h:22
Definition PBDSuspensionConstraintTypes.h:23
static UE_FORCEINLINE_HINT bool IsNearlyEqual(float A, float B, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:388
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592