AddForce is preserved even after I stop applying it

Hi, I have this code:

if(MainComponent && FVector::Dist(GroundTraceHitResult.Location, MainComponent->GetComponentLocation()) > 200.0f)
	MainComponent->AddForce(MainComponent->GetUpVector() * -1000.0f);

I read that AddForce “Should be called every frame for the duration of the force.”, but even when I stop applying it, the force is still preserved, and pawn is still going down

It simulates physics, so it keeps its momentum. If you want it to stop, you have to explicitly tell it to stop.

Ok, how can I do it? I don’t want to stop all the movement, just this force

You can call StopMovementImmediately() on the pawn movement component if you want to stop movement altogether, or if you’d like to maintain horizontal movement but stop vertical movement, you can do something like GetCharacterMovement()->Velocity *= FVector(1,1,0);

Momentum is what keeps it moving as Tuerer mentioned. it will stop eventually.

If its the character you want to move I suggest you use.

Force does not impart movement, force imparts acceleration.
Position is the integral of velocity.
Velocity is the integral of acceleration.
Acceleration is the integral of force (divided by mass.)

Also, if you have an ACharacterMovementComponent involved, know that the Unreal character is not particularly physical; it does a bunch of hacks to make a typical “action game character” move in a satisfying manner, but it doesn’t behave as per the rules of a rigid body simulation.

1 Like