#how to implement smooth character movement with animation that doesnotreset every timeabuttonispress
1 messages · Page 1 of 1 (latest)
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()
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
wait, I'll try now
Oh, it's a vector. It should be == Vector2.ZERO
yes, i wrote it like that, something is wrong, now the animation doesn't finish
if you remove the looping animation of walking, then it almost works, the animation ends, but there is no transition to idle