Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KinematicBody2D: move_and_slide_with_snap won't snap to slopes #26274

Closed
piratesephiroth opened this issue Feb 25, 2019 · 9 comments
Closed

KinematicBody2D: move_and_slide_with_snap won't snap to slopes #26274

piratesephiroth opened this issue Feb 25, 2019 · 9 comments

Comments

@piratesephiroth
Copy link
Contributor

piratesephiroth commented Feb 25, 2019

Godot version:

Godot 3.1 beta 61b41d6

OS/device including version:
Windows 10 x64

Issue description:

EDIT: it was just that move_and_slide_with_snap only snaps to floors and a limit for that is defined by the floor_max_angle argument. The default value is lower than 45º therefore it wouldn't detect the slopes in my example as floors.
Thanks @kaadmy

move_and_slide_with_snap only snaps to straight surfaces.
It completely ignores slopes.

All these tests use Vector2(0,16) as snap

Falling from a 16 pixels-tall tile onto a straight surface. Snaps fine.
flat

Falling from a corner onto a slope, no snapping at all:
slope-polygon

slope_tilemap

Steps to reproduce:
In a 2D Platformer setting, use move_and_slide_with_snap to make a KinematicBody2D slide off a ledge or corner. It will only stay on the floor if there's straight terrain inside the snap vector range.

Minimal reproduction project:
move_and_slide_with_snap-slopeBug.zip

@akien-mga akien-mga added this to the 3.2 milestone Feb 25, 2019
@kaadmy
Copy link
Contributor

kaadmy commented Feb 25, 2019

move_and_slide_with_snap will only snap to floors. The default floor angle is 0.785398 radians, which equals 44.999991 degrees. Setting the slope angle to a few degrees higher fixes this (due to floating point precision issues and margins).

@AttackButton
Copy link
Contributor

I confirm this, even with higher degree angle it is not snapping properly and the stop_on_slope argument still not working. Please don't send this issue to 3.2, it was working a few 3.1 betas ago.

@piratesephiroth
Copy link
Contributor Author

piratesephiroth commented Feb 26, 2019

oh, @kaadmy is correct.
For some reason, 45º is above the default angle of what move_and_slide_with_snap considers to be a floor so it can't be snapped to (even though it isn't particularly more difficult to slide on than 44º).

If we change the floor_max_angle argument to 46º (0.802851 radians) it snaps again.
The code is fine then but perhaps this detail should just be added to the help/documentation.

@AttackButton
Copy link
Contributor

@piratesephiroth Yeah it is snapping but the stop_on_slope argument still not working and it is sliding down slowly.

@piratesephiroth
Copy link
Contributor Author

piratesephiroth commented Feb 26, 2019

@piratesephiroth Yeah it is snapping but the stop_on_slope argument still not working and it is sliding down slowly.

I can confirm stop_on_slope is working, both on move_and_slide and move_and_slide_with_snap.
Did you try beta7?

@svendixon
Copy link

I am using the 3.1 release with stop_on_slope = true, but my character still slides down slopes.

2019-03-24 10-36-37

@piratesephiroth
Copy link
Contributor Author

you should upload a sample project then because as I wrote before, stop_on_slope is working fine here

@svendixon
Copy link

Ok. I created an sample project. Keep in mind, I'm not much of a programmer, so I apologize if it's badly written. Setting up the collision using a RayCast shape fixed the sliding issue for the most part (I thought this was only used to solve constant velocity up and down slopes?). Player sometimes comes off the slope, but that might be my bad code. But it seems using a RayCast shape causes issues with one way platforms. Maybe there is something I am missing?

2019-03-25 02-35-03

slippery_slope.zip

@piratesephiroth
Copy link
Contributor Author

piratesephiroth commented Mar 25, 2019

hmmm.... your character never stops sliding because the x velocity after your lerp calculation never results in 0 on slopes and I think stop_on_slope is only triggered when the body actually stops moving horizontally... is this a problem with Godot? ¯\_(ツ)_/¯

As a test, try making a button set the x velocity to 0 as you slide down a slope and you'll see the character will stay stationary.

(unrelated but I think you should be making those movement calculations in _physics_process)

(also Vector2 has constants you can use to set basic values, like Vector2.ZERO)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants