How Does Mario Movement On Slide Works? Eleanor - dataEcto/super-mario-65 GitHub Wiki
In a normal project when using Rigidbody for player controls, Unity physics system handles the sliding effect on its own. However, for this project, we are doing a manually sliding system to fake the natural sliding effect
We inherit from the normal movement method (details in Genric's page: How Does Movement Work? ) to achieve a coherent control but added a constant force to push Mario according to the slide's direction.
In order to adjust the pushing force's direction, we calculate the ground's slope using two Raycast emitted from the player controller, and covert the slope vector to an angle on the XZ plane. However, this method has its drawback: Mario can possibly be pushed back to the top of the slider if the camera is facing backward. To fix it, we simply forced the input on z coordinate to be 1 (forcing Mario to move forward) and clamped the max angle the camera can turn per frame so that Mario would already fall off the slide before the camera turns backward.