0 votes

I have an Effect node consisting of Node2d > Sprite> AnimationPlayer. This node kills itself once its animation ends.

When my Player node takes damage, I instance this Effect node, set its position to the position of the Player node, and add it as a child of the Player node.

I also have a knockback on my Player node, so that when taking damage, it moves in the appropriate direction.

The problem is that once my effect animation spawns, its position does not get updated with the player, so the player slides out from behind it during its knockback.

Ideally, I want it to move with my player. I thought it was enough just to add it as a child of the player node, but apparently not.

So, my question: How can I link the position of this effect node to that of my player?

I do NOT want to write a script in the effect node (for example, using_process()) which looks for the player and manually follows its position. I am also using this effect elsewhere, and thus don't want ad hoc code like this just for the player.

in Engine by (1,604 points)

1 Answer

0 votes
Best answer

Solved this myself. The question was based on a silly oversight.

Actually, it is enough just to add the node as a child of the parent and set

position = Vector2(0,0)

Position is local to the parent node.

by (1,604 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.