How to animation in Godot ?

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

Hi everyone !!! I’m a completely new guy to Godot Engine. So recently I tried to make a simple platformer 2D game. I finish the movements part and put some animation like run or idle. But after that, I had no idea how to get jump animation to work. I already understand that I have to divide the jump animation into 3 states (start, mid-air, land) also try to use a state machine but it doesn’t work somehow maybe I did sth wrong. Anyway really hope you guys can point out a solution for me and really thank you

In the code below I try to put start jump animation in and seems it kinda works

func _input(_event):

acc.x = 0
if Input.is_action_pressed(input_left):
	acc.x = -max_acceleration
	$Sprite2D.flip_h = true
elif Input.is_action_pressed(input_right):
	acc.x = max_acceleration
	$Sprite2D.flip_h = false

	acc.x = 0

if Input.is_action_just_pressed(input_jump):
	holding_jump = true
	if (not can_hold_jump and can_ground_jump()) or can_double_jump():
if Input.is_action_just_released(input_jump):
	holding_jump = false

I don’t see anything immediatly obvious that would bug out your jump. I think we may need more help and see your can_hold_jump and can_ground_jump, can_double_jump , and jump functions to help you.

However, I did notice you set holding_jump to true whenever the jump input is pressed, regardless as to whether jumping was successful. Not sure if this is intended or not, but it could be a cause of your bug. You are also starting the jump_buffer_timer timer even if a jump was not successful. Maybe that is the cause of your bug

godot_dev_ | 2023-04-27 13:55