#how to implement smooth character movement with animation that doesnotreset every timeabuttonispress

1 messages · Page 1 of 1 (latest)

green ridge
#

the first fragment is how it should be, the second is how it works in my game

#

I think something needs to be changed in the walk_state script

#

here it is extends NodeState

@export var player: Player
@export var animated_sprite_2d: AnimatedSprite2D
@export var speed: int = 60

func _on_physics_process(_delta: float) -> void:
var direction: Vector2 = GameInputEvents.movement_input()

if direction != Vector2.ZERO:
    player.player_direction = direction
    if direction.y < 0 and direction.x == 0:
        animated_sprite_2d.play("walk_back")
    elif direction.y > 0 and direction.x == 0:
        animated_sprite_2d.play("walk_front")
    elif direction.x < 0 and direction.y == 0:
        animated_sprite_2d.play("walk_left")
    elif direction.x > 0 and direction.y == 0:
        animated_sprite_2d.play("walk_right")
    elif direction.x > 0 and direction.y < 0:
        animated_sprite_2d.play("walk_back_right")
    elif direction.x > 0 and direction.y > 0:
        animated_sprite_2d.play("walk_front_right")
    elif direction.x < 0 and direction.y < 0:
        animated_sprite_2d.play("walk_back_left")
    elif direction.x < 0 and direction.y > 0:
        animated_sprite_2d.play("walk_front_left")

    player.velocity = direction * speed
    player.move_and_slide()

func _on_next_transitions() -> void:
if !GameInputEvents.is_movement_input():
transition.emit("Idle")

func _on_enter() -> void:
pass

func _on_exit() -> void:
animated_sprite_2d.stop()

scarlet herald
#

You'll need to decouple your input and your animation playing. I'd probably aim to make the movment smooth, then tie the animation stop/start to whether the character is moving or not

#

Try just adding a "and player.velocity == 0" to the end of the "f !GameInputEvents.is_movement_input():" line

scarlet herald
#

Oh, it's a vector. It should be == Vector2.ZERO

green ridge
green ridge