I am having a problem with limiting the velocity of my player, normally you would just cap the speed of the rigidbody altogether by applying dampening but I am making a game where the player will be in the air a lot and I want them to fly very fast.
After some searching I found the solution seeing if the linear velocity of the player is above the max velocity in the x/z axis and make the acceleration zero in respective axis. This works perfectly accept for the fact that going diagonaly makes the player ba able to go faster than normal.
So I have devised a solution where I have a vector in the same direction as my current horizontal speed but the length of my max speed, and for all four axies I compare the x/z with respective x/y of the max speed vector so when going diagonaly my max speed on both x/z is both ≈0.707.
Again, this solution good until I realized that while in the air, while going straight , I was locked into the very side of the max speed cirkle and needed to "back out" if I wanted to go more diagonaly. (I have made a sketch to show what I think is happening)
Sketch:
Is there an easier way to do this or am I misunderstanding something huge? I would greatly appreciate some help.
Code: