I’m trying to have a simple chest animation were it opens when you interact (UI displays) and then closes when you interact again with the same input. I was obviously able to get the open to work fine but have failed at getting it to play the closed animation.
here’s what i have for the open part. I am very new this is my first project so the code speak goes over my head sometimes.
Your current code is slightly off but you have the right idea.
First you check for the interact input, then you need to check the state of the chest, which is either open or closed. Based on that you play the specific animation.
If you dont have a “chestclose” animation then you can play the “chestopen” animation backwards instead
Try something like so:
var chest_open: bool = false
func player_interact() → void:
if Input.is_action_just_pressed(“interact”) and chest_open:
toggle_inventory.emit(self)
animation_player.play(“chestopen”)
chest_open = true
elif Input.is_action_just_pressed(“interact”) and not chest_open:
toggle_inventory.emit(self)
animation_player.play(“chest_close”)
chest_open = false
every attempt I try and give it a state to check it just skips chestopen and goes straight to close. probably tried a dozen variants of this at least. i also tried getting rid of the close animation and playing open backwards. same result.