AnimationPlayer noob question

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By heavyathan

Hi guys.
I’m facing a issue that is frutating me as I cannot find the trick.

I’m trying to create an explosion effect when a magic bolt impacts something. The approaching is similar to the TPS Demo Shooter, but I use a Area node as root.

The bolt is done following this YT tuto:

My problem is that in the very moment one bolt impacts something, all next bolts are instanced in last status of animation, or this seems. I’ve tried to stop animation before queue_free(), set all parameters as they should be in _ready() but nothing seems to work.

I’m quite sure is a stupid detail but honestly, I’m quite blocked.

My ball scene:

A link to an small video:

Involved code:

func _on_bola_body_entered(body):
if ball_ha_dado == false:
	if body.has_method("dolor"):
		#paso el daño, la posicion de la colision
		body.dolor(DAMAGE, global_transform)
col.disabled =true"explotar")
ball_ha_dado = true

Thank you.

is the code indented properly? ball_ha_dado = true seems to be outside the last if check

vnmk8 | 2021-07-07 01:58

Hi, Vnmk8.

It’s outside, but on purpose. The if stament is just to ensure behind enemies are not being affected due to time gaps until queue_free().

heavyathan | 2021-07-07 06:08

:bust_in_silhouette: Reply From: Dumuz

I haven’t looked at the project, but I’m assuming:“explotar”)

^ Isn’t in the bolt script itself, so it’s not really being uniquely instanced. It looks like it may be getting referenced. So when it goes to explode, all the bolts explode. You may need to make sure this animation player is in the bolt itself, where it can be uniquely instanced with each bolt.

The complete scene is called “bola”, instanced each time player “shoot”, which has the collision and 2 particle nodes, one is “bolt”, and the other “chispas”. The AnimationPlayer is child of “bola”, not from bolt to use the queue_free() of the whole scene.

I’ll try this afternoon to move animationplayer to bolt node and more playarounds.

heavyathan | 2021-07-07 06:16

It would be good to see the script for the variable bolt_anim.

Check and make sure that what you’re calling is the instanced version of the AnimationPlayer and not just the original scene in your ‘FileSystem’.

So it should look something like:

func _on_bola_body_entered(body):
    if ball_ha_dado == false:
        if body.has_method("dolor"):
            body.dolor(DAMAGE, global_transform)
        col.set_deferred("disabled", true)  #Use set_deferred for disabling collision
        body.find_node("AnimationPlayer").play("explotar") #Using the "body" argument to grab which instance's AnimationPlayer we want to use.
        ball_ha_dado = true

Dumuz | 2021-07-07 19:58