cjddmut / Unity-2D-Platformer-Controller

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dropped into any scene for immediate support.
MIT License
865 stars 163 forks source link

Sliding down slopes while also allowing movement upward #75

Open fatboxSoftware opened 5 years ago

fatboxSoftware commented 5 years ago

I've re-purposed this system for a skateboarding game and it's working well. One sticking point I'm trying to figure out is how to get the player to slide back down to the bottom as if gravity were at play, but also allow the player to move up the slope. Right now it does this when I set a low angle not allowing player to move up (slides down nicely)...but again the player cannot move up slopes. I've been digging through the code for a couple of hours looking for what I need to comment out to no avail. Can anyone point me in the right direction?

cjddmut commented 5 years ago

The code that handles all movement is the ApplyMovement function on line 2371

So long as you have the velocity set up it should handle sliding up a ramp. I don't know the details of the design of your game but you should be able to keep the angle shallow to allow sliding but bump the velocity values to imitate pushing on the ground to generate speed. This should allow you to get up slopes.

On Mon, Apr 29, 2019 at 4:38 AM James notifications@github.com wrote:

I've re-purposed this system for a skateboarding game and it's working well. One sticking point I'm trying to figure out is how to get the player to slide back down to the bottom as if gravity were at play, but also allow the player to move up the slope. Right now it does this when I set a low angle not allowing player to move up (slides down nicely)...but again the player cannot move up slopes. I've been digging through the code for a couple of hours looking for what I need to comment out to no avail. Can anyone point me in the right direction?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cjddmut/Unity-2D-Platformer-Controller/issues/75, or mute the thread https://github.com/notifications/unsubscribe-auth/AAW4A34TNAGQMSMXNBIAZ7TPS3M25ANCNFSM4HJCQ7QA .

fatboxSoftware commented 5 years ago

Thank you I will look into this section of code. I appreciate your guidance on where to look. I am able to slide up the slopes really well. It's that once I stop on a slope, the player doesn't slide back down. It sits in one spot. However I've noticed that if I set the allowable degree angle to be very low, in essence telling the script I am not able to go up this slope (it's too steep), the character will slide back down it very nicely if I jump onto the slope. So what I am trying to do is set that allowable slope angle to be high (up to 80 degrees or so) and this allows my player to roll up the slope, but I'd still like to have my player slide back down when I'm not pushing input to go up the slope. Basically like a faux gravity.