Godot Version
4.2.2
Question
trying to set up an idle animation that plays when the player is no longer moving. I’m using a 2d sprite in a 3d world. All other animations work. I’ve tried different line to make it work.
this is how my code is set up right now
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if dead:
return
if event is InputEventMouseMotion:
rotation_degrees.y -= event.relative.x * MOUSE_SENS
if Input.is_action_just_pressed(“left”):
AniSprite.play(“Lwalk”)
if Input.is_action_just_pressed(“right”):
AniSprite.play(“Rwalk”)
if Input.is_action_just_pressed(“forward”):
AniSprite.play(“BackWalk”)
if Input.is_action_just_pressed(“back”):
AniSprite.play(“FrontWalk”)
if input_dir == false:
AniSprite.play(“Idle”)
List of things I’ve tried that hasn’t worked
else:
AniSprite.play("idle) didn’t work
if can_move == false:
AniSprite.play(“idle”)
if !can_move == false:
AniSprite.play(“idle”)
if input_dir == false:
AniSprite.play("Idle")
If anyone has any ideas of what I’m doing wrong, I’d appreciate a comment, anything helps.
put this code in “_process” or “_physics_process”. This code only gets executed when you press a button which you wont do when you want to be idle
1 Like
it tells me identifier not declared in current scope im not sure how to make call for can_move
you dont have a variable called “can_move”
1 Like
try this
extends CharacterBody2D
@onready var AniSprite: AnimationPlayer = $AnimationPlayer
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotation_degrees.y -= event.relative.x * MOUSE_SENS
func _process(delta: float) -> void:
if dead:
return
AniSprite.play("Idle")
if Input.is_action_pressed("left"):
AniSprite.play("Lwalk")
await AniSprite.animation_finished
if Input.is_action_pressed("right"):
AniSprite.play("Rwalk")
await AniSprite.animation_finished
if Input.is_action_pressed("forward"):
AniSprite.play("BackWalk")
await AniSprite.animation_finished
if Input.is_action_pressed("back"):
AniSprite.play("FrontWalk")
await AniSprite.animation_finished
1 Like
sorry for late response started college again
it kinda works it defiantly plays the idle animation but it wont let me play the others when i move my character
Thats because you always override the animation by calling “.play(“idle”)” everyframe