I’m new to Godot. I use it for the second day. I can’t find information on how to solve my problem. There is no way to add running animation and its changeability when moving with the mouse. Either the character is constantly in the “run” animation, or just stands still. I will be very grateful for your help. Here is my code:
extends CharacterBody2D
@export var speed = 250
@onready var anim: AnimatedSprite2D = $AnimatedSprite2D
var click_position = Vector2()
var target_position = Vector2()
func _ready():
click_position = position
anim.play("idle")
func _physics_process(delta:):
if Input.is_action_just_pressed("Rclick"):
click_position = get_global_mouse_position()
if position.distance_to(click_position)>3:
target_position = (click_position - position).normalized()
velocity = target_position * speed
move_and_slide()
I can’t find anything. Help!!!
New contributor
pants228 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.