i’ve tried to make my character jump, but there’s a strange behaviour
if character not doing anything while jump - animation works correctly, but if he goes left or right animation changes to walking
how to fix that? i suppose i need to write some condition, like “while jump animation plays, every other animations stop”
here’s code for jump and animation
func yet_he_jumps(delta):
if is_on_floor():
if Input.is_action_just_pressed("jump"):
current_state = State.Jump
velocity.y = -600
if !is_on_floor() and current_state == State.Jump:
var direction = Input.get_axis("left", "right")
velocity.x += direction*100*delta
func player_anim():
if current_state == State.Idle:
animated_sprite_2d.play("idle")
elif current_state == State.Run:
animated_sprite_2d.play("run_right")
elif current_state == State.Jump:
animated_sprite_2d.play("jump")
func then_he_runs(delta):
var direction = Input.get_axis("left", "right")
if direction:
velocity.x = direction*150
else:
velocity.x = move_toward(velocity.x, 0, 150)
if direction != 0 and is_on_floor():
current_state = State.Run
animated_sprite_2d.flip_h = false if direction > 0 else true