Godot Version
Godot 4.5
Question
can’t make my character move or receive calls to change her sprite, i really have no idea what i’m doing wrong
extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var cordinal_direction : Vector2 = Vector2.DOWN
var direction : Vector2 = Vector2.ZERO
var walk_speed : float = 20
var state : String = "(idle)"
func _ready() -> void:
pass
func _process( delta ):
velocity.y = Input.get_action_strength("up") - Input.get_action_strength("down")
velocity.x = Input.get_action_strength("left") - Input.get_action_strength("right")
velocity += direction * walk_speed * delta
if SetState() == true:
UpdateAnimation()
func _physics_process( delta ):
move_and_slide()
func SetDirection() -> bool:
return true
func SetState() -> bool:
var new_state : String = "(idle)" if direction == Vector2.ZERO else "(walk)"
if state == new_state:
return false
state = new_state
return true
func UpdateAnimation() -> void:
animated_sprite_2d.play(state + AnimationDirection())
func AnimationDirection() -> String:
if cordinal_direction == Vector2.DOWN:
return "back"
elif cordinal_direction == Vector2.UP:
return "front"
elif cordinal_direction == Vector2.LEFT:
return "side-left"
else:
return "side-right"