I'm trying to make some wizard enemy that has 3 spells (Node2Ds) around it following a path with PathFollow2D.

My problem is that, when it attacks, I want each of the spells go towards the player's position one by one, first the circle, then the square and then the triangle. (I don't want them to FOLLOW the player, just go to where the player was).

I tried using an animation player to make their moving animation and THEN changing their destination to be the player's global position changing one of the key values of the animation, but it's not working as expected.

The direction the 3 spells move, x value being 120

With the script right now, the circle spell moves way too fast and it doesn't go to where the player is, probably because the animation is making things worse.

I'm also trying the state machine and it kinda works. This is what my project looks like right now, lot of screenshots sorry:

First part of the code Last part of the code

The state machine

And what the attack animation does (it makes the animatedsprite change to "attacking animation" and calls attack()

I'm sorry if it's a bit confusing or if I'm asking too much, I just want to know if there's an easy way to make Node2Ds move to an specified position and at a lower speed. I'm probably making things harder by using animations... I guess this would be easier if I made the spells separate scenes instead of creating them inside the enemy itself, so then I instance them one by one with a set speed or something... I'm not sure

This is how the problem looks like, everything is broken:

https://gifyu.com/image/SbFpZ

Thank you for the help!

You wouldn't usually use AnimationPlayer for dynamic animation. You would use a Tween. Most likely the easiest thing is to hide the animated spell (set visible to false) and then spawn an identical Sprite in the same position and use a Tween with code to move it where you like.

@cybereality said: You wouldn't usually use AnimationPlayer for dynamic animation. You would use a Tween. Most likely the easiest thing is to hide the animated spell (set visible to false) and then spawn an identical Sprite in the same position and use a Tween with code to move it where you like.

That works so much better, thank you! My only problem now is that the spells move very far away, they don't move to where the player currently is. Am I using the Tween wrong?

Try using global_position instead of position, since newpos. Then it should go from the original of the scene (Vector2(0, 0)) to the player's current position (newpos).

Thinking about it and reading the opening post, what you may want to do is change Vector2(0, 0) to the global position of the circle, so it goes from it's current position to the player position:

tween.interpolate)property(circle, "global_position", circle.global_position, newpos, 3, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

Though I'm not totally positive, but I think it should give closer to the effect you are looking for, where it goes from it's current position to the player's position.

You can pass null as the third parameter and it will use the current position.

@cybereality said: You can pass null as the third parameter and it will use the current position.

Thanks to both of you it kind of works now. The closer the player is to the spells, the slower they will move towards the player, and the further the player is, the faster the spells will move.

Also, because I'm using the idea of hiding the sprites that have no area2d or anything, and then moving the Node2Ds that have the area2ds, I never reset their positions to where they should be to go back to follow the path2d around the enemy, so on the next attack, they will move from the last position they ended up, and not from their initial position (the one inside the pathfollow2d). Getting a bit complicated haha

The Tween works based on time, The parameter @TwistedTwigleg gave is 3 seconds, so it will always be 3 seconds regardless of the distance (meaning faster or slow depending on how far it is). You have to calculate a time that is scaled by the distance so that it is the same speed.

10 months later