Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | R0AR |
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, main_hands, second_hands) 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.