How to fix the player falling from platform?

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

I created a state machine with theses states: idle, run, jump, fall and attack.
When I press the attack button, that’s what happens:
enter image description here

When the platform goes up, the player falls. When goes down, the player flies.
Here’s the code of state_attack:

func state_attack(delta):
	$anims.play(anim + str(dir_sprite))
	yield($anims,"animation_finished")

	if is_on_floor():
		if abs(vel.x) > 0:
			init_run()
		else:
			init_idle()
	else:
		init_fall()

I tried to insert the gravity and move_and_slide in this state, but my charactes falls really fast after que animation of the attack.

I think you should share more code, because the relevant part may be where you handle the movement. I guess that player is not moving when attacking, so the position remains the same while attacking… a kinematicbody2d won’t collide if you dont use one of the movement methods, so you see it flying when platform is going down (actually, the character is just staying at the same point), or falling trhough (actually, it is also just staying at the same point).

p7f | 2020-09-06 15:29