p.UseTargetVelocityOnImpact
p.UseTargetVelocityOnImpact
#Overview
name: p.UseTargetVelocityOnImpact
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
When disabled, we recalculate velocity after impact by comparing our position before we moved to our position after we moved. This doesn\'t work correctly when colliding with physics objects, so setting this to 1 fixes this one the hit object is moving.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.UseTargetVelocityOnImpact
is to control how velocity is recalculated after an impact in character movement, particularly when colliding with physics objects.
This setting variable is primarily used in the Character Movement Component of Unreal Engine’s physics system. It’s specifically utilized in the PhysFalling function, which handles the physics of a character falling.
The value of this variable is set using an FAutoConsoleVariableRef, which allows it to be modified at runtime through console commands. By default, it’s set to 1 (enabled).
The associated variable UseTargetVelocityOnImpact
directly interacts with p.UseTargetVelocityOnImpact
. They share the same value and are used interchangeably in the code.
Developers must be aware that this variable significantly affects how character velocity is calculated after collisions, especially with moving objects. When enabled (set to 1), it improves the accuracy of velocity calculations when colliding with moving physics objects.
Best practices when using this variable include:
- Keep it enabled (set to 1) for most scenarios, especially in games with complex physics interactions.
- If you’re experiencing unexpected behavior in character movement after collisions, particularly with moving objects, consider checking this variable’s state.
- Be cautious when disabling it, as it may lead to incorrect velocity calculations when interacting with moving physics objects.
Regarding the associated variable UseTargetVelocityOnImpact
:
- Its purpose is identical to
p.UseTargetVelocityOnImpact
. - It’s used directly in the PhysFalling function of the CharacterMovementComponent to determine how to calculate velocity after an impact.
- Its value is set by the console variable
p.UseTargetVelocityOnImpact
. - It interacts with other variables in the velocity calculation process, such as Velocity, ContactVelocity, and NewVelocity.
- Developers should be aware that this variable directly affects the physics simulation of falling characters, particularly their interaction with moving objects.
- Best practices include carefully considering any changes to this variable, as it can significantly impact the feel and accuracy of character movement in the game.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:266
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
static int32 UseTargetVelocityOnImpact = 1;
FAutoConsoleVariableRef CVarUseTargetVelocityOnImpact(
TEXT("p.UseTargetVelocityOnImpact"),
UseTargetVelocityOnImpact, TEXT("When disabled, we recalculate velocity after impact by comparing our position before we moved to our position after we moved. This doesn't work correctly when colliding with physics objects, so setting this to 1 fixes this one the hit object is moving."));
static float ClientAuthorityThresholdOnBaseChange = 0.f;
FAutoConsoleVariableRef CVarClientAuthorityThresholdOnBaseChange(
TEXT("p.ClientAuthorityThresholdOnBaseChange"),
ClientAuthorityThresholdOnBaseChange,
#Associated Variable and Callsites
This variable is associated with another variable named UseTargetVelocityOnImpact
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:264
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
TEXT("If enabled, character velocity corrections will be treated as relative to dynamic movement bases."));
static int32 UseTargetVelocityOnImpact = 1;
FAutoConsoleVariableRef CVarUseTargetVelocityOnImpact(
TEXT("p.UseTargetVelocityOnImpact"),
UseTargetVelocityOnImpact, TEXT("When disabled, we recalculate velocity after impact by comparing our position before we moved to our position after we moved. This doesn't work correctly when colliding with physics objects, so setting this to 1 fixes this one the hit object is moving."));
static float ClientAuthorityThresholdOnBaseChange = 0.f;
FAutoConsoleVariableRef CVarClientAuthorityThresholdOnBaseChange(
TEXT("p.ClientAuthorityThresholdOnBaseChange"),
ClientAuthorityThresholdOnBaseChange,
TEXT("When a pawn moves onto or off of a moving base, this can cause an abrupt correction. In these cases, trust the client up to this distance away from the server component location."),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:4888
Scope (from outer to inner):
file
function void UCharacterMovementComponent::PhysFalling
Source code excerpt:
// Compute velocity after deflection (only gravity component for RootMotion)
const UPrimitiveComponent* HitComponent = Hit.GetComponent();
if (CharacterMovementCVars::UseTargetVelocityOnImpact && !Velocity.IsNearlyZero() && MovementBaseUtility::IsSimulatedBase(HitComponent))
{
const FVector ContactVelocity = MovementBaseUtility::GetMovementBaseVelocity(HitComponent, NAME_None) + MovementBaseUtility::GetMovementBaseTangentialVelocity(HitComponent, NAME_None, Hit.ImpactPoint);
const FVector NewVelocity = Velocity - Hit.ImpactNormal * FVector::DotProduct(Velocity - ContactVelocity, Hit.ImpactNormal);
Velocity = HasAnimRootMotion() || CurrentRootMotion.HasOverrideVelocityWithIgnoreZAccumulate() ? FVector(Velocity.X, Velocity.Y, NewVelocity.Z) : NewVelocity;
}
else if (subTimeTickRemaining > UE_KINDA_SMALL_NUMBER && !bJustTeleported)