The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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:
    $AnimationPlayer.play("run")
    motion.x += x_input * ACCELERATION * delta
    motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
    sprite.flip_h = x_input < 0
else:
    $AnimationPlayer.play("idle")

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
else:
    $AnimationPlayer.play("jump")
    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 Frequently asked questions and 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 [email protected] with your username.