UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WheelSystem.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
7#include "Math/Vector.h"
8#include "TireSystem.h"
10#include "VehicleUtility.h"
11
12#if VEHICLE_DEBUGGING_ENABLED
14#endif
15
16namespace Chaos
17{
18
43{
44 // #todo: use this
46 {
50 MISSING
51 };
52
53 // #todo: use this
55 {
56 ROLLING, // wheel speed matches the vehicle ground speed
57 SPINNING, // wheel speed faster than vehicle ground speed
58 LOCKED // wheel is locked and sliding over surface
59 };
60
61 // #todo: use this
63 {
64 Multiply, // default - most correct
66 };
67
69 {
70 UndefinedAxle = 0,
72 Rear
73 };
74
81
83 : Offset(FVector(2.f, 1.f, 0.f))
84 , WheelMass(20.f) // [Kg]
85 , WheelRadius(30.f) // [cm]
86 , WheelWidth(20.f)
87 , MaxSteeringAngle(70)
88 , MaxBrakeTorque(2000.f)
89 , HandbrakeTorque(1000.f)
90 , ABSEnabled(false)
91 , BrakeEnabled(true)
92 , HandbrakeEnabled(true)
93 , SteeringEnabled(true)
94 , EngineEnabled(false)
95 , TractionControlEnabled(false)
96 , TorqueRatio(0.f)
97 , AxleType(EAxleType::UndefinedAxle)
98 , FrictionCombineMethod(EFrictionCombineMethod::Multiply)
99 , ExternalTorqueCombineMethod(EExternalTorqueCombineMethod::None)
100 , FrictionMultiplier(2.0f)
101 , LateralSlipGraphMultiplier(1.0f)
102 , CorneringStiffness(1000.0f)
103 , SideSlipModifier(1.0f)
104 , SlipThreshold(20.0f)
105 , SkidThreshold(20.0f)
106 , MaxSpinRotation(30.0f)
107 {
108
109 }
110
111 // Basic
112 //FSimpleTireConfig Tire;
113
114 // wheel tire
116 float WheelMass; // Mass of wheel [Kg]
117 float WheelRadius; // [cm]
118 float WheelWidth; // [cm]
119
120 int MaxSteeringAngle; // Yaw angle of steering [Degrees]
121
122 // brakes
123 float MaxBrakeTorque; // Braking Torque [Nm]
124 float HandbrakeTorque; // Handbrake Torque [Nm]
125 bool ABSEnabled; // Advanced braking system operational
126
127 // setup
128 bool BrakeEnabled; // Regular brakes are enabled for this wheel
129 bool HandbrakeEnabled; // Handbrake is operational on this wheel
130 bool SteeringEnabled; // Steering is operational on this wheel
131 bool EngineEnabled; // Wheel is driven by an engine
132 bool TractionControlEnabled;// Straight Line Traction Control
133 float TorqueRatio; // Portion of torque going to this wheel (0->1)
134
136
139
144
147
150
151 // #todo: simulated Damage
152 //EWheelDamageStatus DamageStatus;
153 //float BuckleAngle;
154};
155
156
160class CHAOSVEHICLESCORE_API FSimpleWheelSim : public TVehicleSystem<FSimpleWheelConfig>
161{
162public:
163
165
166// Inputs
167
170 {
171 Re = NewRadius;
172 }
173
176 {
177 AngularPosition = PositionIn;
178 }
179
182 {
183 Omega = AngularVelocityIn;
184 }
185
188 {
189 Omega = LinearMetersPerSecondIn / Re;
190 }
191
194 {
195 BrakeTorque = BrakeTorqueIn;
196 bEngineBraking = bEngineBrakingIn;
197 }
198
201 {
202 DriveTorque = EngineTorqueIn;
203 }
204
209
211 {
212 ExternalBrakeTorque = BrakeTorqueIn;
213 bEngineBraking = bEngineBrakingIn;
214 }
215
217 {
218 ExternalDriveTorque = EngineTorqueIn;
219 }
220
223 {
224 GroundVelocityVector = VIn;
225 }
226
229 {
230 ForceIntoSurface = WheelLoadForceIn;
231
232 if (ForceIntoSurface > SMALL_NUMBER)
233 {
234 bInContact = true;
235 }
236 else
237 {
238 bInContact = false;
239 }
240 }
241
244 {
245 SurfaceFriction = InFriction;
246 }
247
249 {
250 bInContact = OnGround;
251 }
252
254 {
255 SteeringAngle = InAngle;
256 }
257
259 {
260 MaxOmega = InMaxOmega;
261 }
262
264 {
265 WheelIndex = InIndex;
266 }
267
268// Outputs
269
274 {
275 FVehicleUtility::ClampNormalRange(SlipIn);
276
277 // typical slip angle graph; normalized scales
278 // Friction between 0 and 1 for values of slip between 0 and 1
279 float FunctionResult = 1.125f * (1.0f - exp(-20.0f * SlipIn)) - 0.25f * SlipIn;
280 return FMath::Max(0.0f, FMath::Min(1.0f, FunctionResult));
281 }
282
285 {
286 return ForceFromFriction;
287 }
288
290 float GetEffectiveRadius() const
291 {
292 return Re;
293 }
294
296 float GetAngularPosition() const
297 {
298 return AngularPosition;
299 }
300
302 float GetAngularVelocity() const
303 {
304 return Omega;
305 }
306
309 {
310 return OmegaToRPM(Omega);
311 }
312
314 bool InContact() const
315 {
316 return bInContact;
317 }
318
319 bool IsSlipping() const
320 {
321 return (FMath::Abs(GetSlipMagnitude()) > Setup().SlipThreshold);
322 }
323
324 bool IsSkidding() const
325 {
326 return (FMath::Abs(GetSkidMagnitude()) > Setup().SkidThreshold);
327 }
328 bool IsABSActivated() const
329 {
330 return bABSActivated;
331 }
332
333 float GetSteeringAngle() const
334 {
335 return SteeringAngle;
336 }
337
340 {
341 return Sx;
342 }
343
345 {
346 return FMath::Clamp(RadToDeg(SlipAngle) / 30.0f, 0.f, 1.f);
347 }
348
350 float GetWheelLoadForce() const
351 {
352 return ForceIntoSurface;
353 }
354
356 float GetSurfaceFriction() const
357 {
358 return SurfaceFriction;
359 }
360
362 float GetSlipAngle() const
363 {
364 return SlipAngle;
365 }
366
368 float GetDriveTorque() const
369 {
370 return DriveTorque;
371 }
372
374 float GetBrakeTorque() const
375 {
376 return BrakeTorque;
377 }
378
380 float GetRoadSpeed() const
381 {
382 return GroundVelocityVector.X;
383 }
384
387 {
388 return Omega * Re;
389 }
390
393 float GetSlipMagnitude() const
394 {
395 return GetWheelGroundSpeed() - GetRoadSpeed();
396 }
397
400 float GetSkidMagnitude() const
401 {
402 return GroundVelocityVector.Y;
403 }
404
405
412 void Simulate(float DeltaTime);
413
414
416 {
417 MassPerWheel = VehicleMassPerWheel;
418 }
419
420public:
421 bool BrakeEnabled; // Regular brakes are enabled for this wheel
422 bool HandbrakeEnabled; // Handbrake is operational on this wheel
423 bool SteeringEnabled; // Steering is operational on this wheel
424 bool EngineEnabled; // Wheel is driven by an engine
425 bool TractionControlEnabled;// Straight Line Traction Control
426 bool ABSEnabled; // Advanced braking system operational
434
435 float Re; // [cm] Effective Wheel Radius could change dynamically if get a flat?, tire shreds
436 float Omega; // [radians/sec] Wheel Rotation Angular Velocity
437 float Sx;
438 float Inertia;
439 // In
440 float DriveTorque; // [N.m]
441 float BrakeTorque; // [N.m]
442 float ForceIntoSurface; // [N]
443 FVector GroundVelocityVector; // [Unreal Units cm.s-1]
444 float AngularPosition; // [radians]
445 float SteeringAngle; // [degrees ATM]
447 float MaxOmega;
448
449 float ExternalDriveTorque; // [N.m]
450 float ExternalBrakeTorque; // [N.m]
451
454
455 // Wheel transform
456
457 float SlipVelocity; // Relative velocity between tire patch and ground ?? vector ??
458 float SlipAngle; // Angle between wheel forwards and velocity vector
459 bool bInContact; // Is tire in contact with the ground or free in the air
460 uint32 WheelIndex; // purely for debugging purposes
461 bool bEngineBraking; // Is the braking force coming from the engine
462
463 public:
464 // debug for now
470 float Spin;
475
476};
477
478
480{
481 TArray<uint16> WheelIndex; // reference to wheels on this axle
483};
484
486{
487public:
488
489 FAxleSim();
490
491 void Simulate(float DeltaTime) {}
492
494
495};
496
497} // namespace Chaos
498
499#if VEHICLE_DEBUGGING_ENABLED
501#endif
#define UE_ENABLE_OPTIMIZATION
Definition CoreMiscDefines.h:60
#define UE_DISABLE_OPTIMIZATION
Definition CoreMiscDefines.h:59
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#define SMALL_NUMBER
Definition UnrealMathUtility.h:66
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition WheelSystem.h:486
FAxleConfig Setup
Definition WheelSystem.h:493
void Simulate(float DeltaTime)
Definition WheelSystem.h:491
Definition VehicleUtility.h:89
Definition WheelSystem.h:161
void SetBrakeTorqueOverride(float BrakeTorqueIn, bool bEngineBrakingIn=false)
Definition WheelSystem.h:210
float GetSurfaceFriction() const
Definition WheelSystem.h:356
float GetSlipAngle() const
Definition WheelSystem.h:362
float HandbrakeTorque
Definition WheelSystem.h:432
bool bEngineBraking
Definition WheelSystem.h:461
void SetVehicleGroundSpeed(const FVector &VIn)
Definition WheelSystem.h:222
float MaxSteeringAngle
Definition WheelSystem.h:430
float MaxOmega
Definition WheelSystem.h:447
void SetDriveTorqueOverride(float EngineTorqueIn)
Definition WheelSystem.h:216
void SetDriveTorque(float EngineTorqueIn)
Definition WheelSystem.h:200
FSimpleWheelConfig::EExternalTorqueCombineMethod ExternalTorqueCombineMethod
Definition WheelSystem.h:433
bool IsSkidding() const
Definition WheelSystem.h:324
uint32 WheelIndex
Definition WheelSystem.h:460
void SetWheelRadius(float NewRadius)
Definition WheelSystem.h:169
FVector GroundVelocityVector
Definition WheelSystem.h:443
float SlipAngle
Definition WheelSystem.h:458
bool TractionControlEnabled
Definition WheelSystem.h:425
bool bClipping
Definition WheelSystem.h:473
void SetMassPerWheel(float VehicleMassPerWheel)
Definition WheelSystem.h:415
float AppliedLinearBrakeForce
Definition WheelSystem.h:466
float Inertia
Definition WheelSystem.h:438
void SetTorqueCombineMethod(FSimpleWheelConfig::EExternalTorqueCombineMethod InCombineMethod)
Definition WheelSystem.h:205
float LongitudinalAdhesiveLimit
Definition WheelSystem.h:467
bool HandbrakeEnabled
Definition WheelSystem.h:422
float GetAngularPosition() const
Definition WheelSystem.h:296
bool EngineEnabled
Definition WheelSystem.h:424
void SetMatchingSpeed(float LinearMetersPerSecondIn)
Definition WheelSystem.h:187
float LateralSlipGraphMultiplier
Definition WheelSystem.h:428
float FrictionMultiplier
Definition WheelSystem.h:427
float LateralAdhesiveLimit
Definition WheelSystem.h:468
bool bInContact
Definition WheelSystem.h:459
float GetWheelRPM()
Definition WheelSystem.h:308
float GetBrakeTorque() const
Definition WheelSystem.h:374
float ExternalBrakeTorque
Definition WheelSystem.h:450
float Sx
Definition WheelSystem.h:437
float Omega
Definition WheelSystem.h:436
void SetOnGround(bool OnGround)
Definition WheelSystem.h:248
bool ABSEnabled
Definition WheelSystem.h:426
float DriveTorque
Definition WheelSystem.h:440
FVector GetForceFromFriction() const
Definition WheelSystem.h:284
float SlipVelocity
Definition WheelSystem.h:457
void SetSurfaceFriction(float InFriction)
Definition WheelSystem.h:243
float MaxBrakeTorque
Definition WheelSystem.h:431
float BrakeTorque
Definition WheelSystem.h:441
float GetNormalizedLateralSlip() const
Definition WheelSystem.h:344
float GetDriveTorque() const
Definition WheelSystem.h:368
bool SteeringEnabled
Definition WheelSystem.h:423
float GetSkidMagnitude() const
Definition WheelSystem.h:400
bool IsSlipping() const
Definition WheelSystem.h:319
float AvailableGrip
Definition WheelSystem.h:471
float AppliedLinearDriveForce
Definition WheelSystem.h:465
float SteeringAngle
Definition WheelSystem.h:445
float GetRoadSpeed() const
Definition WheelSystem.h:380
float SurfaceFriction
Definition WheelSystem.h:446
bool InContact() const
Definition WheelSystem.h:314
float GetAngularVelocity() const
Definition WheelSystem.h:302
float AngularPosition
Definition WheelSystem.h:444
bool bABSActivated
Definition WheelSystem.h:474
bool IsABSActivated() const
Definition WheelSystem.h:328
float Spin
Definition WheelSystem.h:470
static float GetNormalisedFrictionFromSlipAngle(float SlipIn)
Definition WheelSystem.h:273
void SetWheelIndex(uint32 InIndex)
Definition WheelSystem.h:263
float MassPerWheel
Definition WheelSystem.h:453
float GetWheelLoadForce() const
Definition WheelSystem.h:350
void SetWheelLoadForce(float WheelLoadForceIn)
Definition WheelSystem.h:228
void SetBrakeTorque(float BrakeTorqueIn, bool bEngineBrakingIn=false)
Definition WheelSystem.h:193
float ExternalDriveTorque
Definition WheelSystem.h:449
void SetMaxOmega(float InMaxOmega)
Definition WheelSystem.h:258
FVector InputForces
Definition WheelSystem.h:472
float Re
Definition WheelSystem.h:435
float GetSlipMagnitude() const
Definition WheelSystem.h:393
float ForceIntoSurface
Definition WheelSystem.h:442
float SideSlipModifier
Definition WheelSystem.h:469
void SetSteeringAngle(float InAngle)
Definition WheelSystem.h:253
float GetSteeringAngle() const
Definition WheelSystem.h:333
float CorneringStiffness
Definition WheelSystem.h:429
float GetWheelGroundSpeed() const
Definition WheelSystem.h:386
void SetAngularVelocity(float AngularVelocityIn)
Definition WheelSystem.h:181
float GetNormalizedLongitudinalSlip() const
Definition WheelSystem.h:339
bool BrakeEnabled
Definition WheelSystem.h:421
FVector ForceFromFriction
Definition WheelSystem.h:452
float GetEffectiveRadius() const
Definition WheelSystem.h:290
void SetAngularPosition(float PositionIn)
Definition WheelSystem.h:175
Definition Array.h:670
Definition VehicleSystemTemplate.h:13
Definition SkeletalMeshComponent.h:307
FORCEINLINE float RadToDeg(float InRad)
Definition VehicleUtility.h:282
FORCEINLINE float OmegaToRPM(float Omega)
Definition VehicleUtility.h:181
@ false
Definition radaudio_common.h:23
Definition WheelSystem.h:480
float RollbarScaling
Definition WheelSystem.h:482
TArray< uint16 > WheelIndex
Definition WheelSystem.h:481
Definition WheelSystem.h:43
FSimpleWheelConfig()
Definition WheelSystem.h:82
float TorqueRatio
Definition WheelSystem.h:133
EAxleType AxleType
Definition WheelSystem.h:135
EExternalTorqueCombineMethod ExternalTorqueCombineMethod
Definition WheelSystem.h:138
EExternalTorqueCombineMethod
Definition WheelSystem.h:76
@ Override
Definition WheelSystem.h:78
float WheelWidth
Definition WheelSystem.h:118
FVector Offset
Definition WheelSystem.h:115
float SlipThreshold
Definition WheelSystem.h:145
bool SteeringEnabled
Definition WheelSystem.h:130
EFrictionCombineMethod FrictionCombineMethod
Definition WheelSystem.h:137
FGraph LateralSlipGraph
Definition WheelSystem.h:148
float LateralSlipGraphMultiplier
Definition WheelSystem.h:141
bool HandbrakeEnabled
Definition WheelSystem.h:129
bool ABSEnabled
Definition WheelSystem.h:125
int MaxSteeringAngle
Definition WheelSystem.h:120
float HandbrakeTorque
Definition WheelSystem.h:124
float MaxBrakeTorque
Definition WheelSystem.h:123
float SideSlipModifier
Definition WheelSystem.h:143
float CorneringStiffness
Definition WheelSystem.h:142
float SkidThreshold
Definition WheelSystem.h:146
float WheelRadius
Definition WheelSystem.h:117
EFrictionCombineMethod
Definition WheelSystem.h:63
@ Multiply
Definition WheelSystem.h:64
float WheelMass
Definition WheelSystem.h:116
EAxleType
Definition WheelSystem.h:69
@ Front
Definition WheelSystem.h:71
EWheelSimulationStatus
Definition WheelSystem.h:55
@ SPINNING
Definition WheelSystem.h:57
@ ROLLING
Definition WheelSystem.h:56
bool TractionControlEnabled
Definition WheelSystem.h:132
float FrictionMultiplier
Definition WheelSystem.h:140
bool EngineEnabled
Definition WheelSystem.h:131
float MaxSpinRotation
Definition WheelSystem.h:149
EWheelDamageStatus
Definition WheelSystem.h:46
@ BUCKLED
Definition WheelSystem.h:48
@ FLAT
Definition WheelSystem.h:49
@ NONE
Definition WheelSystem.h:47
bool BrakeEnabled
Definition WheelSystem.h:128
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592