(Update!) Better Knockbacks using Add Force and Linear Drag Only - Unity 2022
Chris' Tutorials
I've been experimenting and I find one way is to increase the linear drag on the rigidbody set in Dynamic mode. Instead of the Lerp to 0 (removing those lines entirely), you can set the rb.drag to a higher amount to get it to stop faster (Stop drag vs moving drag as 2 different variables for different character states). This lets the knockback apply more correctly.
So for movement
// Move animation and add velocity // Accelerate the player while run direction is pressed (limited by rigidbody linear drag) rb.AddForce(moveInput * moveSpeed * Time.fixedDeltaTime, ForceMode2D.Force);
And in the scripts where you apply force to the player
// Apply force to the slime // Impulse for instantaneous forces rb.AddForce(knockback, ForceMode2D.Impulse);
Letting the linear drag handle the knockback lets the rigidbody physics smooth out the velocity between the normal run and the knockback impulse. ... https://www.youtube.com/watch?v=yna_u1OASy0
16943344 Bytes