p.Chaos.Suspension.SlopeThreshold

p.Chaos.Suspension.SlopeThreshold

#Overview

name: p.Chaos.Suspension.SlopeThreshold

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Suspension.SlopeThreshold is to control the anti-slide mechanism for vehicles on slopes in Unreal Engine’s Chaos physics system. It defines the threshold angle at which the anti-slide mechanism is employed to prevent vehicles from sliding down steep slopes.

This setting variable is primarily used in the Chaos physics subsystem, specifically in the suspension constraints module. It’s part of the experimental Chaos physics engine in Unreal Engine 5.

The value of this variable is set in the file PBDSuspensionConstraints.cpp. It’s initialized with a default value of 0.707f, which corresponds to a slope angle of approximately 45 degrees (cos(45°) ≈ 0.707).

This variable interacts with several other variables in the same system:

  1. Chaos_Suspension_SlopeSpeedThreshold
  2. Chaos_Suspension_SlopeSpeedBlendThreshold

These variables work together to control the behavior of vehicles on slopes at different speeds.

Developers must be aware that this variable represents the cosine of the slope angle, not the angle itself. For example, a value of 0.866 corresponds to a 30-degree slope, while 0.6428 corresponds to a 50-degree slope.

Best practices when using this variable include:

  1. Adjusting it in conjunction with the speed thresholds for a balanced vehicle behavior.
  2. Testing thoroughly with various slope angles and vehicle speeds to ensure desired behavior.
  3. Consider the specific requirements of your game’s terrain and vehicle physics when setting this value.

Regarding the associated variable Chaos_Suspension_SlopeThreshold:

This is the actual variable that stores the slope threshold value. It’s declared and initialized in the same file (PBDSuspensionConstraints.cpp) and is directly linked to the console variable p.Chaos.Suspension.SlopeThreshold.

The purpose of Chaos_Suspension_SlopeThreshold is the same as p.Chaos.Suspension.SlopeThreshold - it’s used in the actual physics calculations to determine when to apply the anti-slide mechanism.

This variable is used in the ApplySingle function of the FPBDSuspensionConstraints class. It’s compared against the Z component of the surface normal to determine if the anti-slide mechanism should be applied.

Developers should be aware that changing p.Chaos.Suspension.SlopeThreshold via the console or configuration files will directly affect Chaos_Suspension_SlopeThreshold, and thus the behavior of vehicles on slopes in the game.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDSuspensionConstraints.cpp:21

Scope: file

Source code excerpt:


float Chaos_Suspension_SlopeThreshold = 0.707f;	// = Cos(SlopeAngle)
FAutoConsoleVariableRef CVarChaosSuspensionSlopeThreshold(TEXT("p.Chaos.Suspension.SlopeThreshold"), Chaos_Suspension_SlopeThreshold, TEXT("Slope threshold below which the anti-slide on slope mechanism is employed, value = Cos(AlopeAngle), i.e. for 50 degree slope = 0.6428, 30 degree slope = 0.866"));

float Chaos_Suspension_SlopeSpeedThreshold = 1.0f; // MPH
FAutoConsoleVariableRef CVarChaosSuspensionSlopeSpeedThreshold(TEXT("p.Chaos.Suspension.SlopeSpeedThreshold"), Chaos_Suspension_SlopeSpeedThreshold, TEXT("Speed below which the anti-slide on slope mechanism is fully employed"));

float Chaos_Suspension_SlopeSpeedBlendThreshold = 10.0f; // MPH
FAutoConsoleVariableRef CVarChaosSuspensionSlopeSpeedBlendThreshold(TEXT("p.Chaos.Suspension.SlopeSpeedBlendThreshold"), Chaos_Suspension_SlopeSpeedBlendThreshold, TEXT("Speed below which the anti-slide on slope blend mechanism starts"));

#Associated Variable and Callsites

This variable is associated with another variable named Chaos_Suspension_SlopeThreshold. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDSuspensionConstraints.cpp:20

Scope: file

Source code excerpt:

FAutoConsoleVariableRef CVarChaosSuspensionMaxPushout(TEXT("p.Chaos.Suspension.MaxPushout"), Chaos_Suspension_MaxPushout, TEXT("Chaos Suspension Max Pushout Value"));

float Chaos_Suspension_SlopeThreshold = 0.707f;	// = Cos(SlopeAngle)
FAutoConsoleVariableRef CVarChaosSuspensionSlopeThreshold(TEXT("p.Chaos.Suspension.SlopeThreshold"), Chaos_Suspension_SlopeThreshold, TEXT("Slope threshold below which the anti-slide on slope mechanism is employed, value = Cos(AlopeAngle), i.e. for 50 degree slope = 0.6428, 30 degree slope = 0.866"));

float Chaos_Suspension_SlopeSpeedThreshold = 1.0f; // MPH
FAutoConsoleVariableRef CVarChaosSuspensionSlopeSpeedThreshold(TEXT("p.Chaos.Suspension.SlopeSpeedThreshold"), Chaos_Suspension_SlopeSpeedThreshold, TEXT("Speed below which the anti-slide on slope mechanism is fully employed"));

float Chaos_Suspension_SlopeSpeedBlendThreshold = 10.0f; // MPH
FAutoConsoleVariableRef CVarChaosSuspensionSlopeSpeedBlendThreshold(TEXT("p.Chaos.Suspension.SlopeSpeedBlendThreshold"), Chaos_Suspension_SlopeSpeedBlendThreshold, TEXT("Speed below which the anti-slide on slope blend mechanism starts"));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDSuspensionConstraints.cpp:386

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDSuspensionConstraints::ApplySingle

Source code excerpt:


			// Ingeniously blends the surface normal at low speeds to stop vehicles sliding slowly down steep slopes
			if (SurfaceNormal.Z > Chaos_Suspension_SlopeThreshold)
			{
				if (Body.V().SquaredLength() < (SpeedThreshold * SpeedThreshold))
				{
					SurfaceNormal = FVec3(0.f, 0.f, 1.f);
				}
				else