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")
    print(anim.get_track_count())
    #print(anim.track_get_key_value(0,0))
    #print(anim.track_get_key_value(0,1))
    var p:Vector3 = self.transform.origin
    print("p   " + String(p))
    var p1:Vector3 = p
    p1.y = p1.y + 2

    print("p1   " + String(p1))
    anim.track_set_key_value(0,0,p)
    anim.track_set_key_value(0,1,p1)
    anim.track_set_key_value(0,2,p)

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:
1
p (14.8615, -4.71206, 0)
p1 (14.8615, -2.71206, 0)
1
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
https://drive.google.com/file/d/1mBz6DETuDAoxY-MoAXLLQS7VzpV4G6w-/view?usp=sharing

Enemy game object screenshot

https://drive.google.com/file/d/1Nd-qN6y43ZAAIkJHbPsPUH9HZJsKt7Ap/view?usp=sharing

Thanks.

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

Node2D
-Sprite
-Animation

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,459 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.

config_animation()
$AnimationPlayer.play("Topple",-1,3)

Thanks.

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.