Download

How and when the player movement is REALLY applied?

Hi all,
I don’t understand how and when the character movement is applied.
Using the TopDown C++ example, here is the code snippet


void ATopDownPlayerController::PlayerTick(float DeltaTime)
{
	FVector v1 = GetPawn()->GetActorLocation();
	Super::PlayerTick(DeltaTime);
	FVector v2 = GetPawn()->GetActorLocation();
}


Question 1)
From what I understand PlayerTick is responsible for character movement so I wonder why v1 and v2 are always equal? I would expect them to be different if character moves.

Question 2)
Take a look at this new character


void ATopDownPlayerNewSpeedController::PlayerTick(float DeltaTime)
{
	FVector v1 = GetPawn()->GetActorLocation();
	Super::PlayerTick(DeltaTime * 100);
	FVector v2 = GetPawn()->GetActorLocation();
}

Why ATopDownPlayer and ATopDownPlayerNewSpeed have the same speed? I would expect the latter to move 100 times faster.

Question 3)
I need to calculate player position at time T so I am looking for a function like this pseudo-code:


FVector v1 = GetActorLocation();
AddMovementInput(vector, Value);
ApplyMovement(my_custom_delta_time);
FVector v2 = GetActorLocation();

having with v2 the new actor position

Do you have any tips on “ApplyMovement(float)” function could be implemented?

Thank you very much!
Gianluca

It seems the function StartPhysics(DeltaSeconds) could be the function I am looking for

Ok here’s my experience:

The tick component will do a lot of things, but when the component has authority (it’s single player or is server) will call the PerformMovement, wich is the function responsible of computing the new Movement.
Inside the PerformMovement, it will do a pletora of things, like looking for root motion, etc, But the method we are interested is StartNewPhysics.

This method will, depending of the current movement mode (MOVE_Walking, MOVE_Falling, etc) start the physics simulation.
Each movement mode has a method wich is called if that movement is the current one.

MOVE_Walking => PhysWalking
MOVE_Falling => PhysFalling

Etc.
The magic happens HERE, specifically, on the SafeMoveUpdatedComponent method inside of each one (this method tries to move the component,if it encounters a collision, it tries to resolve it).

I know all of this because i created a custom movement component wich has 2 more movement modes and it works REALLY WELL, better in my opinion that snapping this code on the character and hopping the movement component doesn’t snap