Download

Dodging Mechanic: Issues, workarounds, and help needed applying constrained movement to a character

I’ve been trying to implement dodge mechanics, but have run into a lot of interesting road blocks along the way. If anyone has a different perspective or another approach to suggest I’d love to hear your thoughts.

My initial goal:
Adding a simple dodge mechanic, wherein on a button press the player character moves in a defined direction, over a defined distance, over a defined time. This is all handled in single player, so no replication is required.
E.g. On dodging the player character moves 1 metre, and takes 2 seconds to do so.

Triggering the move and determining the direction vector is simple, but actually applying the movement is where my design started to fall apart.

Attempted movement methods:
Root Motion
Root motion is the simplest and most straight forward approach, but it slaves all the particulars of the dodge to the animation montage. Ideally the character would be able to upgrade/modify the aspects of their dodge, and this approach would require tweaking the animation for each iteration.

AddImpulse/AddForce/Launch
This method is simple and easy to tweak– in fact, it would be perfect if not for the fact that the player character is ludicrously affected when they dodge while in the air. As there is no friction opposing their movement, they go flying in the direction of the dodge.

AddVelocity
Being able to tweak the character movement (e.g. dampen forward movement when dodging laterally) is nice, but it runs into the same friction issue as AddImpulse.

Possible workarounds:
Brute force the in-air issue by checking IsFalling, and applying a weaker impulse if it returns true.
*Problem: Isn’t at all elegant, requires fine tuning to get the effect of the impulses to match up, and might not scale well in areas with different physics. *

Alternatively brute force the root motion by adding a time factor to the animation, thus controlling the speed and maintaining a constant distance traveled.
Problem: Can’t easily adjust the distance traveled, and possibly warps the animation when slowed too much.

I’ve also tried playing around with ground friction and braking speeds to make movement in the air match movement on the ground (to no effect, although I’m likely doing something wrong)
Problem: Apart from not getting it to work, it’s still very janky (especially because the modified values would have to apply for duration of the roll). Using the IsFalling check would be simpler.

Completely redesigning the dodge, so that it raytraces for collision in the direction of the dodge, and then lerps the player to empty space/the collision site. This appeals to me because it would give me full control over the distance to be dodged, and the time it takes to complete the dodge.
Problem: Needlessly complicated? Possible collision related issues (e.g. foliage, projectiles, small terrain, etc. triggering false positives on the ray check) resulting in odd interactions.

Please point out if I’ve missed any obvious approaches! Thanks for your time.