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

move_and_slide_with_snap() gliding down slopes and workarounds dont work since RC3-5 etc #47042

Closed
robertarnborg opened this issue Mar 16, 2021 · 7 comments · Fixed by #47277
Closed

Comments

@robertarnborg
Copy link

robertarnborg commented Mar 16, 2021

Godot version:
3.2.4.rc3 - rc5

OS/device including version:
windows 10

Issue description:
My characters are sliding down slopes now, and workaround fixes don't consistently work.
Something happened with this since I started testing rc4 and rc5.

I have used -get_floor_normal() as snap or Vector2.DOWN * 8 with move_and_slide_with_snap(motion, snap, Vector2.UP, true) etc. before but this doesn't stop character from sliding down the slopes. Plus something with the snap vector seems off. The -get_floor_normal() as snap vector seemed to be the sturdiest before but not anymore.

In RC2 it still worked! Now no...

made a simple project with player.gd code down below.

SlidingDownSnap8
MoveAndSlideStopOnSlopesNotWorking.zip

Minimal reproduction project:

@Calinou
Copy link
Member

Calinou commented Mar 16, 2021

In RC2 it still worked! Now no...

Did it work in 3.2.4rc3?

@robertarnborg
Copy link
Author

robertarnborg commented Mar 16, 2021

nope, it is not working in rc3. So something happened between rc2 and rc3

@robertarnborg robertarnborg changed the title move_and_slide_with_snap() gliding down slopes and workarounds dont work since RC4-5 etc move_and_slide_with_snap() gliding down slopes and workarounds dont work since RC3-5 etc Mar 16, 2021
@pouleyKetchoupp
Copy link
Contributor

I can actually reproduce a similar issue in 3.2.3 as well, but the effect is more obvious in 3.2.4 RC4 and later (in 3.2.3 the character is slowly sliding).

The reason is stop_on_slopes works only when the motion is against the up vector, so it's not applied if the character is immobile.

It's documented here:
https://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html#class-kinematicbody2d-method-move-and-slide

If stop_on_slope is true, body will not slide on slopes when you include gravity in linear_velocity and the body is standing still.

I'd like to add an option to apply stop_on_slope when the character is not moving at all, which would work in your case. But because it might break compatibility for some other scenarios, it would be safer to make this change in 4.0 as an extra property after godotengine/godot-proposals#2184 is done.

As a workaround, what you can do is to change two things in your script:

  • When the character is standing, make sure to apply some gravity in the y component of your motion:
if !is_jumping:
	#motion.y = 0
	motion.y = gravity * delta
  • Because you apply friction, the x component is not set to 0 directly when there's no input, so the character is not considered standing still by move_and_slide and keeps being pushed down the slope. In order to prevent this, you can discard the x component returned by move_and_slide (which includes the character being pushed diagonally) and keep the value you apply from the character controls:
#motion = move_and_slide_with_snap(motion, snap, Vector2.UP, true, 4)
var result_motion = move_and_slide_with_snap(motion, snap, Vector2.UP, true, 4)
motion.y = result_motion.y

It will allow friction to actually decrease motion.x over time until it's low enough for stop_on_slope to work. In 3.2.3 and 3.2.4 RC builds, the character is able to stop completely on a slope.

@robertarnborg
Copy link
Author

I know, the sliding has always been an issue regarding stop on slope. Something assumed to be a simple feature usually never is. Having been able to use negative floor normal in the snap, it worked before in 3.2.4 RC2 and before in stoping player from sliding down so hope someone can change it back to when it worked 🙂

ill try your work around and see how that goes 🍺

@robertarnborg
Copy link
Author

allright maybe it is working, just differently. Changed collision margin to 0.01 and snap at 8 seems to work again.

@pouleyKetchoupp
Copy link
Contributor

Since you mentioned changing the safe margin in order to fix your issue, I've linked the PRs #47277/#47278 that improve safe margin documentation to this issue.

With that and my previous explanation I will consider this issue closed (after the documentation changes get merged) but let me know if you still have any outstanding question or problem related to this issue.

@Clamshell64
Copy link

Not sure if people will come by here anymore, but if you want constant speed up slopes as well as down them, I've found that changing motion.y = gravity * delta to
if motion.y > gravity * delta:
motion.y = gravity * delta
will do the trick.

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

Successfully merging a pull request may close this issue.

5 participants