0 votes

I've seen a lot of threads about this but no solutions for 2D. I've got moveandslide on and when I walk into a tileset corner, my player starts rapidly switching between being on the ground and being in the air. How can I fix that?

in Engine by (19 points)
edited by

Could we see some example code, or a screenshot of what is happening?

func _physics_process(delta):
var x_input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")

if x_input != 0:
    motion.x += x_input * ACCELERATION * delta
    motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
    sprite.flip_h = x_input < 0

motion.y += GRAVITY * delta

if is_on_floor():
    if x_input == 0:
        motion.x = lerp(motion.x, 0, FRICTION)
    if Input.is_action_just_pressed("ui_jump"):
        motion.y = -JUMP_FORCE
    if Input.is_action_just_released("ui_jump") and motion.y < -JUMP_FORCE/2:
        motion.y = -JUMP_FORCE/2
    if x_input == 0:
        motion.x = lerp(motion.x, 0, AIR_RESISTANCE)
motion = move_and_slide(motion, Vector2.UP)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.