#Can you spawn an object and animate it from the same Animation Player?

1 messages · Page 1 of 1 (latest)

mint jungle
#

TLDR: Is it possible for an Animation Player (including call method tracks) to instantiate an object, add it to the scene tree, and then assign it to an existing animation track to be animated? (Use case is spawning a projectile and then animating its arc, and deleting it at the end)

I'm making a game inspired by Pokemon and I'm trying to figure out the best way to handle attack animations. The biggest hurdle I've come up against so far is that I want to have one place where I go to edit everything about each animation - I don't want to have to edit both code and an Animation Player's tracks, for instance.
However, my animations need to be able to add objects (usually projectiles) to the scene and then animate them. I don't know how to have an Animation Player have a track for an object that isn't in the scene yet, or to set that object to the track once it spawns. I don't mind writing some helper functions I can call with method call tracks to do this.

I'm aware I could just have the projectile object always in the scene and just turned off or sitting offscreen, then mess with it when the animation plays, but I don't know what all my animations will be yet and if one move uses 40 different projectiles it seems silly to have 40 objects sitting in the scene tree in every battle, just in case.

In the example below, I tried having the animation be its own scene, which I can instantiate and then delete when I'm done, but it means I can't animate the monsters already in the scene.

As a bonus, advice on ways to make it easier to animate attacks in both directions (player attacking opponent and opponent attacking player) would be welcome. Video is a proof of concept animation for reference.

scenic citrus
#

look into node of animation tree "animation_finished(animation_name)" you could accomplish this for when animation finish it then calls a function from another item e.x enemy.takeDamage(dmg)
where enemy is enemy. take damage is code where it take dmg and subtract shield/resistance etc

and obviously you can change this as needed. where you can also implement animations on player/enemy or anything like that

and if you want to make it so you got 1 animation for a bunch of moves. animate an invisble node, and have the move/particl folow the nodes path/cords.

mint jungle
#

Thanks, yeah I don’t have any issues making things happen after an animation plays. The issue is with having animation players have tracks for objects that aren’t in the scene until runtime, and adding those objects to those tracks

#

The particle following the invisible object is not a bad idea, though I can see managing that being really clunky and requiring me to manage both code and tracks for each animation, which is exactly what I’m trying to avoid