I am trying to play an animation of a character in my game when it touches a monster (the character and monster are located in different scenes).
Why access it from another scene?
Your player should be the one to detect the collision and play his own animation.
Either via area or physics body, look into their signals to set up animation changes.
Considering that the player and the monster are on the same level of the node tree in the main scene, for example, you could use something like this inside the monster’s main class:
get_parent().get_node("Player/AnimationTree").play("animation_name")
Whereas animation_player is in the order specified in the code.
From my understanding using get_parent() is not ideal if avoidable.
I also am not understanding why another scene needs to call player, either have player detect the enemy, or have enemy send a signal to player. Easy, and more straightforward.
We know this, but he may be learning so my intention was to teach. Of course I wouldn’t do it like that, but I think that instead of questioning him, I’d rather give him a way to help him.
Sorry, if I came across combative, that wasn’t my intention.
Yes, that makes sense, though in the endeavor to teach l try and note if it isn’t the best idea and maybe give an alternative solution. Also, to search for what they are wanting to accomplish, rather than what they want to do (if what they want to do isn’t good practice). I also find (at least personally for me) questioning allows me to think through the process to figure out what exactly I am trying to accomplish, and the best way to do so. My endeavor in questioning isn’t to minimize his efforts but rather draw out why they want to do it the way they are trying.
I want to know his rationale in wanting to access the animation from another scene. It could be that what he is really asking is to have an animation play, when interacting with another scene. This would prompt another response.
Usually, I try to give more concrete examples myself, unfortunately lately I’ve been responding on my phone, which is a lot harder to write code examples on.
@jarbeans11 What I would do is set up in the player script a collision detection code in _physics_process. You’d call a func that would play your animation when your player detects collision with the enemy. This can all be handled in the players script.
Depending on your needs you can either use Area2D/3D for detecting when another body has entered it, and use its built in signals to initiate your animation.
Or you can look into using the physics of CharacterBody2D/3D for detecting when your player has ran into the enemy.
Which you use depends on you and how you are wanting to set-up your game.
I would recommend looking up a tutorial on youtube or a written one about handling/detecting collisions to better understand this feature if you aren’t familiar with it.
Or if you have a more specific question about collision I’d be happy to help give clarity.