Godot 4.3
I’m following this tutorial: https://www.youtube.com/watch?v=it0lsREGdmc&t=3148s and am around 53 minutes in. I changed the direction in the idle state to player.player_direction like instructed, but now my character will not enter the walk state. II press the input keys and nothing happens. here is my code for both the idle and walk states:
idle:
‘’'gdscript
extends NodeState
@export var player: Player
@export var animated_sprite_2d: AnimatedSprite2D
func _on_process(_delta : float) → void:
if player.player_direction == Vector2.UP:
animated_sprite_2d.play(“up_idle”)
elif player.player_direction == Vector2.DOWN:
animated_sprite_2d.play(“down_idle”)
elif player.player_direction == Vector2.LEFT:
animated_sprite_2d.play(“left_idle”)
elif player.player_direction == Vector2.RIGHT:
animated_sprite_2d.play(“right_idle”)
else:
animated_sprite_2d.play(“down_idle”)
func _on_physics_process(_delta : float) → void:
pass
func _on_next_transitions() → void:
GameInputEvents.is_movement_input()
if GameInputEvents.is_movement_input():
transition.emit("walk")
func _on_enter() → void:
pass
func _on_exit() → void:
animated_sprite_2d.stop()
‘’’
walk:
‘’'gdscript
extends NodeState
@export var player: Player
@export var animated_sprite_2d: AnimatedSprite2D
@export var speed = 50
func _on_process(_delta : float) → void:
pass
func _on_physics_process(_delta : float) → void:
var direction: Vector2 = GameInputEvents.movement_input()
if direction == Vector2.UP:
animated_sprite_2d.play("up_walk")
elif direction == Vector2.DOWN:
animated_sprite_2d.play("down_walk")
elif direction == Vector2.LEFT:
animated_sprite_2d.play("left_walk")
elif direction == Vector2.RIGHT:
animated_sprite_2d.play("right_walk")
if direction != Vector2.ZERO:
player.player_direction = direction
player.velocity = direction * speed
player.move_and_slide()
func _on_next_transitions() → void:
GameInputEvents.is_movement_input()
if !GameInputEvents.is_movement_input():
transition.emit("idle")
func _on_enter() → void:
pass
func _on_exit() → void:
animated_sprite_2d.stop()
‘’‘’