delayed animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sakura37

i’m using a kinematicbody2d with two sprites:hair and body. every sprite has an AnimationPlayer. i set the animations for running and the idle state. All have the same animation lenght and the animation is done frame by frame. I tried continuous, discrete and triggered but after the third loop the hair starts to be delayed and when my body is down my hair is up and so on.

This is my code:(i’m not done with the movement, but i wanted to make sure my animations work)

Update: it isn’t delayed when i’m using a 1linex6columns sprite sheet, but when i use a 2linesx6columns sprite sheet it gets delayed

func _physics_process(delta):
if Input.is_action_pressed(“ui_right”):
velocity.x = SPEED
$body/bodyAnimation.play(“right_moving”)
$hair/hairAnimation.play(“right1-1”)

elif Input.is_action_pressed("ui_left"):
	velocity.x = -SPEED
	$body/bodyAnimation.play("right_moving")
	$hair/hairAnimation.play("right1-1")
else: 
	velocity.x = 0
	if is_on_floor() : 
		$body/bodyAnimation.play("idle")
		$hair/hairAnimation.play("idle")

I don’t know much about animation in the engine. But the delay could be down to one starting, and then, once that first animation is properly started, the next one is started. So how do you start them at the same time? I don’t entirely know how to tackle this problem.

You may have to rely on signals. Have the animations hear for a signal. That may start them at the same time. There’s that, or you may have to put the hair and body animations together into one AnimationPlayer, and have that start when your character moves.

Ertain | 2019-08-20 23:37

Hello! I tried signals, and is still delaying. I don’t want to have 2 animations into one Animation Player, because you as a player can customize your character so the only solution i know for this is having a lot of animations for every hair. Maybe you know another solution.(like changing the value of the line inside the code, because on my first row will be a purple hair,second row-blue hair etc. I’m using a sprite sheet)

Sakura37 | 2019-08-21 09:18

Alright so
For those who have the same problem as me:
For me it works only if you have 1 line, and if you want to change the color, save a sprite sheet for every color of the hair and then just change the texture in code. I’m still waiting for a better solution, but until then i guess i will have to settle down with this.

Sakura37 | 2019-08-21 10:23