• 2D
  • How do I set animations for jumping left if I don't want to flip the character?

Hello Guys, I've been trying to set un animations for little 3 here, but I can't seem to find the way to set different sprite sheets for each of the directions the character is moving towards.

Please check 3's stitches, these battle scars deserve to be shown in all their glory:

I want to create a 2d platform game with a retro feel but not with a retro look, and the character has, as you can see on the pictures, certain details that might be lost if a standard horizontal flip is done whenever the character moves to the left.

Check out how this should look:

This is the run right animation:

This is the run left animation:

This is the idle right animation:

This is the idle left animation: (notice that if we flip this one the number 3 on 3's chest will be mirrored and she or he will not like that)

And finally we have the jump left and jump right "animations" which are placeholders for the moment, (I hope to come up with something better soon):

I'm an artist and not a programmer, and I've been searching for a solution for this problem to no avail. I mean, it has been possible to set up the walking and idle animations using multiple variations and combinations of Input.is_action_pressed('ui_right') and $AnimatedSprite.play(), that seems to work, but whenever the character needs to jump it seems that I can't find a way to use the jump left and jump right sprites.

Can any of you handsome code sculptors give me a hand on this matter, or point me in the direction of some tutorial, video, or tarot reading that can help little 3 be herself (or himself), I'll really appreciate any help and guidance, thanks in advance.

Welcome to the forums @f4bs3000!

I would recommend storing the direction the player is facing in a class variable, and then changing that variable based on player input. Something like this:

extends KinematicBody2D

var facing_direction = “left”
# other variables here (velocity, speed, etc)

func _process(delta):
	if (Input.is_action_pressed(“movement_left”)):
		# handle movement, adding velocity, etc.
		facing_direction = “left”
		# change the animation
		_change_animation(“run”)
	elif (Input.is_action_pressed(“movement_right”)):
		# handle movement, adding velocity, etc.
		facing_direction = “right”
		# change the animation
		_change_animation(“run”)
	else:
		# change the animation
		_change_aniamtion(“idle”)

# a helper function to make changing animations easier
func _change_animation(animation_state):
	if (animation_state == “idle”):
		if (facing_direction == “left”):
			$AnimatedSprite.play(“idle_left”)
		elif (facing_direction == “right”):
			$AnimatedSprite.play(“idle_right”)
	elif (animated_state == “run”):
		if (facing_direction == “left”):
			$AnimatedSprite.play(“run_left”)
		elif (facing_direction == “right”):
			$AnimatedSprite.play(“run_right”)
	# Same thing for all of the other animations that need to
	# take the direction into account.

Something like the code above is how I would handle it. I did not include any movement code or anything like that, but there are various tutorial showing how to achieve platformer movement in Godot that can do a much better job explaining it than I can here. Additionally, the code above does not check to see if the animation is already playing or not before changing it.

Regardless, hopefully the code above helps show one possible way to handle changing animations correctly based on the direction the character is moving in.

2 months later

Thanks for the help, sorry for the late answer, but I was working on something else. I was able to animate the character the way I needed it, I used an animation player and an animation tree. I found how to do it on this video:

I hope this helps the community if somebody needs to have the same type of animation.

Here's a gif of the result, Is not that clear, but if you squint your eyes a little, you'll notice the 3 on the character's body changes accordingly, we have idle left and right, jump left and right, and fall left and right:

Cheers!