Last active
October 26, 2021 18:26
-
-
Save iamjoeysox/0d7c2b0be3771135ba05b4223bb24f9b to your computer and use it in GitHub Desktop.
Prevent KineticBody2D from sliding on slopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If grounded set gravity vector to be inverse floor normal. | |
# That way your character is "falling" flat against the slope and doesn't slide. | |
# I fixed this by setting velocity y to zero when is_on_floor is true. | |
for i in get_slide_count(): | |
var collision:KinematicCollision = get_slide_collision(i) | |
if collision.normal.y < 0.5: | |
#angle is bellow 45 degrees (90 would be 1.0) | |
gravityDir = collision.normal | |
# New better way | |
move_and_slide_with_snap(velocity, Vector2(0, 20), up, false, 4, rad2deg(90)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment