I’m fairly new to Unity, and am trying to implement custom player movement, which is working fine, except I’m a little stumped around max velocity handling.
I’m not using AddForce to my rigidbody, instead just adjusting the velocity, as it provides movement closer to what I’m aiming for.
At first, using
if (velocity.magnitude > maxSpeed) worked fine, but now I’m running into issues where I want external forces (explosions, general knockback) are also limited.
The first thing that came to mind was prevent input if at
maxSpeed, but this runs into a lot of issues with 3D rotational movement where you now can’t drag the character in the opposite direction (cause input is disabled over x speed).
Does anyone have any ideas how to get around this?
// not the actual code, but essentially what I'm doing rotateWithMouseInput(); if (Input.GetKey(forward)) moveForward(); else if (Input.GetKey(backward)) moveBackward(); if (velocity.magnitude > maxSpeed) velocity = velocity.normalized * maxSpeed;