Make character stop upon reaching its destination with AddMovementInput()

Hello everyone,

I’m making a game where the character moves along a grid. I want the player, from its starting position, to interpolate with movement towards the center of the next tile and stop immediately when he reached the tile.

I’ve already adjusted the acceleration and the deceleration of the character movement component to be extremely high so it can stop instantly.

void UFighterMovementComponent::CalcVelocity(float DeltaTime, float Friction, bool bFluid, float BrakingDeceleration)
{
	Super::CalcVelocity(DeltaTime, Friction, bFluid, BrakingDeceleration);
	Velocity = GetMaxSpeed() * Acceleration.GetSafeNormal();
}

Here’s my current approach.

void AFighter::PerformTileMovementSub(FVector _TargetLocation, FVector _Direction, float _Scale)
{
	ElapsedTime = 0.0f;
	TimeToMove = 0.2f; 

	OriginalLocation = GetActorLocation();

	GetWorldTimerManager().SetTimer(MovementTimerHandle, [this]
		{
			// If the character is at the target location, stop moving
			if (ElapsedTime < TimeToMove)
			{
					// Find the next target location
					InterpolatedLocation = FMath::Lerp(OriginalLocation, TargetLocation, (ElapsedTime / TimeToMove));

					// Remaining Distance
					RemainingDistance = TargetLocation - InterpolatedLocation;

					// Move
					AddMovementInput(TargetDirection * RemainingDistance, Scale);

					// Add Elapsed Time
					ElapsedTime += GetWorld()->GetDeltaSeconds();
			}
			else 
			{
				if (!FighterMovementComponent->IsMovementInProgress())
				{
					// Alert the state machine
					onTileReached.ExecuteIfBound();

					// Clear the timer when the movement is complete
					GetWorldTimerManager().ClearTimer(MovementTimerHandle);
				}
				else {
					FighterMovementComponent->StopActiveMovement();
					FighterMovementComponent->StopMovementImmediately();
				}
					
			}
		},
		GetWorld()->GetDeltaSeconds(), true, 0.0f);
}

The issue is my characters sometimes goes over the targetlocation or stop before it by 2 to 5 units. It’s extremely frustrating, I would want it to stop when he reached the destination.

I cannot check the distance from its location to his targetlocation because this approach does not scale at all with speed. (A character with high speed will override the check by a couple frames)

Is it because once a movement is registered, it cannot be stopped until it’s over ? What would be a better way to approach this problem ?