+1 vote

I am new to Godot and I have searched for this question on reddit and here, but the answers are not working for me.

I have separated my player's body parts (bodies, heads, mainhands, secondhands) into different frames but they are in one texture. The reason I have done this is that I want each body part to play a different animation based on the situation. For example when the player is holding a staff and running I want MainHandAnimation to show hold animation while the rest of the body parts show run animation.

To solve this I made a Sprite with 4 different AnimationPlayer nodes as its children. Each AnimationPlayer is for one body part only. In the player's script I play animations after each other but instead of showing all the body parts at once the sprite only shows the lowest AnimationPlayer

For example in a structure like this:

----Area2D
-------- CollisionShape2D
-------- Sprite
------------ BodyAnimation (=AnimationPlayer)
------------ SecondHandAnimation (=AnimationPlayer)
------------ HeadAnimation (=AnimationPlayer)
------------ MainHandAnimation (=AnimationPlayer)

Running this code will only Show MainHandAnimation and not the other ones.

$Sprite/HeadAnimation.play("walk")
$Sprite/BodyAnimation.play("walk")
$Sprite/MainHandAnimation.play("hold" if is_holding else "walk")
$Sprite/SecondHandAnimation.play("walk")

The frames have transparent background so they should be shown on top of each other without any problems.

in Engine by (16 points)

1 Answer

+1 vote
Best answer

As far as I know to solve your problem you would need 4 Sprite nodes, even if all 4 of them would have the same texture. Then you would use each AnimationPlayer node to animate each Sprite. It seams that the way you are doing it now one AnimationPlayer is overriding the other since they are changing the same Sprite.

This video may be of help: How to Make a Run Cycle Using Cutout Animations in Godot 3.0

by (244 points)
selected by

I thought the way you are describing is the correct way to do it but the answer to this question mislead me. I don't know how it is accepted as the best answer and has 2 upvotes! Thanks for the clarification and the video. They were very helpful. I'll wait a day and if no better answers were given, I'll choose this as the best answer.

Hi, ROAR. That answer is correct for that question because in that case each AnimationPlayer will animate different properties. One of them will animate the "frame" property (for the movement animation) and the other will animate the "visible" property (for the blinking effect when the character takes damage). In your case all AnimationPlayer nodes change the same property of the same node. That's why it did not work.

Oh... That makes sense. Thank you so much!

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 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 webmaster@godotengine.org with your username.