For context I have a Sprint, during that sprint state i am not allowed to crouch unless im moving backward, backward left, or backward right.
The problem is when im sprinting directly left or right and i turn my camera quickly while spamming crouch there is a small window that during the turn it lets me crouch and obviously i dont want that
When you turn your character, the rotation is applied before you “push” in that direction and your velocity is changed. This means that you can happen to be “moving backwards” for a tick even if you were actually holding the forward button as long as you rotate 180° in a tick.
You have several ways to prevent that:
Limit your rotation speed. Make it so you can’t turn more than 44.9° degrees a tick. Check how it feels on low frame-rates though or with lag spikes/frame drops.
Delay the decision. Have the player moving backwards at lest for 0.5s to allow the crouch. Usually you can mask it like some kind of “momentum”
Tie it up to the input. Have the player needing to hold the back button in order to crouch. This is client only so it might be cheated.
There are probably more ways I cant think of right now but you get the gist.
Thanks alot, i think im just gonna hold off on it now till I find what i think is the best solution that fits for what i want.
I think the delay would probably work best out of the three, and it probably wouldnt make much difference gameplay wise, I just prefer things to be as reactive as possible