The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Trying to topple enemy game object's instance when got hit by player's bullet.
Animation works but the toppled game object globaltransform.origin changes to the last enemy game object's instance globaltransform.origin. When the animation starts to play the enemy game object instance 1 is positioned at enemy game object's instance no.2's position and ends the animation there.

I used only two instances of the same enemy game object. The following code is in the script of the enemy game object.

func configAnimation():
    var anim = $AnimationPlayer.get_animation("Topple")
    var p:Vector3 = self.transform.origin
    print("p   " + String(p))
    var p1:Vector3 = p
    p1.y = p1.y + 2

    print("p1   " + String(p1))

I connected the animation_finished signal to the AnimationPlayer node and got the position of the game object instance number one starting and ending the animation at the position of game object instance number 2.
The Output is like this:
p (14.8615, -4.71206, 0)
p1 (14.8615, -2.71206, 0)
p (10.2427, -4.71206, 0)
p1 (10.2427, -2.71206, 0)

Anim Finished
(10.2427, -4.71206, 0)

Any suggestion will be helpful. Thanks.

Godot version Version 3.2.3 stable
in Engine by (14 points)

do you have a single animation node or an animation node for each enemy?

I have one single enemy object in which i have the animation player node. I added multiple instances of this enemy object in to the main scene.

main scene screenshot

Enemy game object screenshot


1 Answer

0 votes

i'm not sure because i dont know how you arranged the enemy scene,but I can see 2 reasons:

1) you are calling ConfigAnimation only at the beginning: if that's the case you are freezing the starting position into P, therefore everytime the animation player starts it brings back the enemy into P before making it topple.

2) there is a "bug" in the animationplayer: when referring to the property of a node to animate, sometimes it write down the path comprhensive of the Node name. Eg: if you animate the position of the sprite in this configuration


if you click on the the animation track name it will show .../Node2D/Sprite:position:y: this does not work for multiple instance of Node2D, as they would have different names, so each animation player will always animate only the first instanced object.
Change it toSprite:position:y

Anyway, you are using the animation node in a complex way, it would be much easier if you topple the mesh node only, instead of the entire enemy (like in my example with the sprite).
in this way you can set up the animation node directly in the editor, because the translation would be relative to the parent (the enemy node), so P would aways be Vector3(0,0,0) and P1 Vector3(0,2,0), regardless of the enemy node actual position

by (1,514 points)
edited by

Thanks Andrea. I called the config animation method in the func _ready() method of the enemy game object script.
Then I changed it to be called just after the player bullet hit the enemy. It worked as expected.



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.