How to stop your player climbing up/sliding off slopes

Have you ever noticed that your character slides up or down slopes when using the move_and_slide function in Godot? In this video I’m going to go over how to stop your character sliding up or down slopes in Godot 3.4. It’s never good when your player controller slides on slopes unless you’re intending for it to happen. So what is there to do?

I’m back again this time with a problem and a few solutions. But I don’t know if it’s the best solution but it is a solution

At the start of the week I was going to start on menus…. but I Distracted with this issue.

I was contemplating adding wall running to my game and I started placing blocks in a level. And I noticed that wall running is basically built into Godot. You pretty much always slide on slopes…

What Do I mean by that?

Move and Slide… has an issue with the upwards momentum.

Move and Slide With Snap alleviates the issue but on slopes greater than the max angle, it reverts back to the previous issue, you’re back to sliding down any slope over that angle.

so what do you do?

I tried googling for a solution because I genuinely had no idea but there’s were only video about move and slide with snap. Which as I said, doesn’t really solve this issue.

So How did I get around it? Well I turned to the community which might be a first for me and I put a post on the Godot subreddit.

They provided Some Helpful ideas..

So With their Ideas I went about drafting a solution.

Idea one.

If on wall velocity y clamps to zero. Works okay but what I’ve been told is that when these collisions are taking place, the x velocity get’s translated into the y velocity and that leads to upwards momentum.

The next thing I did is try locking the axis, there’s a lot of potential here this could be a pretty solid solution so I’ll walk you through this one.

First I’ve got a really simple function called wall check. That’s called in my movement states.

Other Options?

We Could have Wall ray cast that pushed back on the input.

Manipulating input feels better than velocity since it’s more subtle

Using get slide collission as a supplement to put the player away from the wall when player is not facing the wall

but get_slide_collisions technique is not 100% viable.

I use this technique because it feels the most natural. Still some jank though…

Bouncy on the walls ect. Not a huge deal since player will only notice when trying to break the game anyway.

Other solution with 100% max angle snap, would need to use something else to test the ground for jump suitability since is on floor will always be true. So you could bunny hop up walls.

Watch on YouTube!

Get The FPSTemplate Here!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *