Premise
I’m using a custom MovementComponent which derives from UPawnMovementComponent. From what I noticed, differently from a UCharacterMovementComponent, it does not include any time-step handling.
I handle all movement logic (e.g., walking, jumping, falling, etc.) with a Finite State Machine I implemented; each state (GroundedState, JumpingState, FallingState, etc.) has its own Enter, Execute and Exit methods.
What I do in these state methods is just modifying MovementComponent->Velocity (for example, based on the Input, or applying my gravity when falling). I don’t use DeltaTime in any way inside of these methods.
Then, in the TickComponent method of my MovementComponent, I just update the FSM and call the Execute method of the relevant state the Pawn is in. This gets the Velocity modified by the state methods as said before.
Still in the TickComponent method, I do:
FVector Delta = Velocity * DeltaTime;
SafeMoveUpdatedComponent(Delta, SomeRotation, true, Hit);
…and the Pawn moves/jumps/falls accordingly.
The Problem
With changing framerates, I get different results on different machines. For example, let’s take the Falling state. In the Execute method of Falling state, I just do:
MoveComp->Velocity.Z -= 25.F;
I see the character falling with some speed at 60FPS. I see the same character with the same code falling differently at 30FPS, 10FPS, and so on.
I know why it’s happening, and I get I have to implement some kind of time-step management. I delved into the UcharacterMovementComponent and saw that movement methods such as Phys_Walking do use deltaTime and Iterations, but I wasn’t able to reproduce this kind of time-step handling in my own scenario.
I’ve read several articles and blog posts about fixing the time-step (one above all: http://gafferongames.com/game-physics/fix-your-timestep/).
The Question
Let’s say I want to implement the Semi-Fixed solution proposed in that link above; how should ago about it?
-
can I use the DeltaTime that get passed in the TickComponent function? Or should I calculate my own as per that article?
-
is my overall implementation fine at all? (I mean, having different FSM states just modifying Velocity, and then just multiplying it by DeltaTime?)
-
where exactly should I implement the Semi-Fixed stuff? Is the TickComponent the right place to do that? Or should I do that in the FSM states?
Thanks!