Topic was automatically imported from the old Question2Answer platform.
Asked By
Socrates
I have a KinematicBody2d based player character and want to add items, like weapons, etc. to the character. Currently I’m doing:
current_weapon = preload("path to weapon.tscn").instance()
add_child(current_weapon)
This works fine and add the weapon instance as expected. However each weapon also has multiple animations that should be played based on the character’s state and I can’t find a way to access the weapon’s AnimationPlayer node from the player character script. I’ve tried:
But you can try creating an animation_player variable in the weapon script.
In weapon script:
onready var animation_player = get_node("AnimationPlayer")
Then, when you reference the weapon from your player script, you can just call this variable which belongs to the weapon.
In player script:
if state == "Shooting":
current_weapon.animation_player.play("Fire")
It turned out I was just doing something dumb in the code that set which animation was playing, but thank you very much for the answer, I appreciate it.