Character Off Ledge Handling
â Last Updated : December 20, 2022
đŞ Prequisite Knowledge (Optional)
Describe Initial Knowledge that reader need to know before reading this article
â Key Question / Problem / Issue
When character is moving over the edge, the default movement is straight forward (zero vertical velocity).
â Expected Output/Definition of Done
When character is moving over the edge, the character should carry out the vertical momentum.
đ Resulting Solution
When a character, in this case, a skater is moving on a ramp, the expected behavior is he/she jumps up carrying the vertical momentum, the same should be applies when the character is moving on a downhill ledge, he/she should jump down the ledge. But Unrealâs CharacterMovement default behavior dictates that the character jumps straight forward, ignoring the momentum from previous movement.
Red is default behavior Green is expected behavior
The problem can be fixed by using CharacterMovementâs OnWalkingOffLedge event
By setting CharacterMovement.Velocity to the previously stored CharacterMovementâs LastUpdatevelocity inside the CharacterMovementâs OnWalkingOffLedge event handler, the character will jump off the ledge while preserving the momentum
But a new problem appears, CharacterMovement.SetVelocity is not synchronized between players, it only happens on server/host. Players jump properly on server, but on client, the multiplayer reconciliation system will force the clientâs player movement back to default behavior.
Red is clientâs player Green is on serverâs player
The first attempt to fix the new problem is using RPC to call the WalkingOffLedge function on Server (from client). But the result is not good since thereâs a delay between the time player (clientâs) is moving off ledge and the time the WalkingOffLedge is called, the delay is small but enough to make player miss their jump.
The 2nd attempt to fix is to temporarily make the client authoritative when the client is jumping (WalkingOffLedge) then switch back to server authoritative when the client finished jumping. It can be achieved by using the âServerAcceptClientAuthoritativePositionâ and âIgnoreClientMovementErrorChecksAndCorrectionâ node
When jumping starts
When jumping ends
â ď¸ Note that the client also must switch back to server authoritative when the player dies/falls. â ď¸
No Comments