How to do RPG animations?

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

Hi, I’m relatively new to the engine, and I was wondering how to do walking animations for the player of an RPG.

Here’s my code: `extends KinematicBody2D

var move_speed = 200
var acceleration = 200
var motion = Vector2()

func _get_input():
motion = Vector2()
if Input.is_action_pressed(“ui_up”):
motion.y -= 1

if Input.is_action_pressed("ui_down"):
	motion.y += 1

if Input.is_action_pressed("ui_right"):
	motion.x += 1

if Input.is_action_pressed("ui_left"):
	motion.x -= 1
motion = motion.normalized() * move_speed

func get_anim():
motion = Vector2()
var facing_up = false
var facing_down = true
if motion.x < 0:
$Sprite.flip_h = true
elif motion.x > 0:
$Sprite.flip_h = false

if motion.y > 0:
	facing_down = true
elif motion.y < 0:
	facing_up = true
	if facing_down:
	elif facing_up:

func _physics_process(delta):
motion = move_and_slide(motion)

func _on_VisibilityNotifier2D_screen_exited():
print(“Player off screen”)`

:bust_in_silhouette: Reply From: Panda_Scientist
if v.y != 0 and not is_on_floor():
	$Sprite.animation = 'jump'
elif v.x != 0:
	$Sprite.animation = 'walk'
	$Sprite.animation = 'idle'


This is what my code looks like for a similar situation. Change the animation variable in your AnimatedSprite node to the one that you want to use, and then play the animation at the end of _physics_process with .play(). Of course this doesn’t include flip_h because i was using a simple sprite that didn’t need to be flipped, but I hope my example helps.