Proper way to implement custom movements?

I’ve been trying to figure out what’s the proper way to implement custom movements.
I want to make different skills which may involve special movements. Dash forward for a time with a constant speed, jetpack, dodge sideways with predefined distance and speed.
It’s really important that the implementation must work in multiplayer, since the game I’m making is multiplayer only.

What I tried:

  • Launch: Sets character in “falling” state, even tho it’s not falling, and it’s more like adding a bonus velocity, rather than overwriting it
  • Setting velocity: works well in single player, however when running on client(control) side, braking kicks in because I’m not giving “Acceleration”, only providing velocity, and it shortens my velocity, making my dash shorter on client side.
  • Impulse: as documented, it’s only good for one time force
  • Force: DeltaTime is calculated twice. Once when adding it into the velocity, and velocity itself is multiplied by deltaTime before adding into Position. So it’s not constant, heavily framerate dependent( not to mention it’s impossible to set it to a normal value ). Braking is also kicking in

What is currently halfway working: Setting velocity directly, but in my derived character movement component class, overwriting the CalcVelocity function, removing the “braking” calculation while my custom movement is on.
This is only partly working because on client side it can “jitter” at the end of the movement. Probably client is updating longer (or shorter) time than server is

Obviously this is a hack, and I want to know the proper way to do it, and preferably with client prediction( so the game does not need to wait until the server acknowledges the custom move ).


You can implement any number of custom movement logic in movement comp or you can create whole new custom movement comp from scratch.
However i think first solution is easier and you can still use epic’s character movement logic.

To use custom movement logic you need override this function in your movement component.

virtual void PhysCustom(float deltaTime, int32 Iterations) override;

If you set your movement mode to custom engine will call this function in each frame like he call other movement modes normally.

Then in this function you can do your own logic, replication, client prediction etc…
you can switch on enum if you wanna more custom logic inside of this function…

Hey there.
Thank you for your answer, but that would mean I need to implement everything the default movement has, again. That would be silly just for a dash.
However I found an amazing thing hidden in the engine: Root motions. Not the ones from the animation, the ones you can define in the game.
My example:

    FRootMotionSource_ConstantForce* ConstantForce = new FRootMotionSource_ConstantForce();
    ConstantForce->InstanceName = TEXT( "Katana_Dash" );
    ConstantForce->AccumulateMode = ERootMotionAccumulateMode::Additive;
    ConstantForce->Priority = 5;
    ConstantForce->Force = Velocity;
    ConstantForce->Duration = TimeToDash;
    ConstantForce->StrengthOverTime = nullptr;
    ConstantForce->FinishVelocityParams.Mode = ERootMotionFinishVelocityMode::MaintainLastRootMotionVelocity;
    DashRootMotionID = Character->GetCharacterMovement()->ApplyRootMotionSource( ConstantForce );

And voilah! IT does exactly what I needed!
Im pretty happy about it. Replicates great( from server to clients ), predicts great if I start it on client side, then send an RPC to server which starts the same root motion

Nah, extending custom movement mode not means you need reimplement everything. Exactly means you can add custom movements and use default movements too… but your solution also works.

but you asked proper way to add custom movement :smiley:
thats the proper way :wink:

anyway glad you figured out

Thank you for that Root Motion Force hint!

I’m having troubles while trying to use the FRootMotionSource_MoveToDynamicForce as explained here Help with Root Motion Forces (not animation related) - Unreal Engine Forums

If someone can help with this or is having issues, maybe we can find usefull info toguether.