I have an Unity project in which i want to control a player in a similar way to Source games, and so far i am clipping each input to the speed in the player’s coordinates, by using
transform.InverseTransformDirection( GetComponent<Rigidbody>().velocity )
after which i pass each of the player input vector direction through this function :
private float FLSMF ( float aInputVelocity, float aMaximumVelocityOnAxis, float aSpeedOnAxis ) { if ( Mod( aSpeedOnAxis ) >= aMaximumVelocityOnAxis ) { if( Sign( aSpeedOnAxis ) != Sign ( aInputVelocity ) ) { if ( Mod( aSpeedOnAxis + aInputVelocity ) > aMaximumVelocityOnAxis ) { return Sign ( aInputVelocity ) * ( aMaximumVelocityOnAxis + Mod( aSpeedOnAxis ) ); } return aInputVelocity; } return 0; } if( Mod( aSpeedOnAxis + aInputVelocity ) > aMaximumVelocityOnAxis ) { return Sign( aInputVelocity ) * ( aMaximumVelocityOnAxis - Mod( aSpeedOnAxis ) ); } return aInputVelocity; }
There is only one problem : whenever i turn and strafe and walk forwards or backwards, the speed increases dramatically. I tried solving it by comparing each processed velocity axis to the velocity rotated by the difference in the rotations between the last 2 FixedUpdate’s. So far nothing worked, aside from driving the drag factor through the roof.
My best guess is that when turning, the unclipped X axis of the vector bleeds into the Z axis when turning, which can’t add anything, but cant stop the X axis from interfering because the forward key is pressed.
There is no issue when only one of the input axis are used, the speed remaining consistent when turning.
I tried to implement this function especially so i dont have to use any drag, to allow the player to be flung by other things, like grapples and explosions ( this issues is present irrespective of said external factors )
If you want to, i will share the entire code, but its messy and i dont think it would help.
Any ideeas how to solve it?
Edit : yes, i have normalized the input vector. The speed increases to more than triple of the maximum, in as few as 2 turns.