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 getinput():
motion = Vector2()
if Input.isactionpressed("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 getanim():
motion = Vector2()
var facingup = false
var facingdown = true
if motion.x < 0:
$Sprite.play("Horizon")
$Sprite.fliph = true
elif motion.x > 0:
$Sprite.play("Horizon")
$Sprite.fliph = false
else:
$Sprite.play("HorizonIdle")
if motion.y > 0:
facing_down = true
$Sprite.play("Down")
elif motion.y < 0:
facing_up = true
$Sprite.play("Up")
else:
if facing_down:
$Sprite.play("Down_Idle")
elif facing_up:
$Sprite.play("Up_Idle")
func physicsprocess(delta):
getinput()
getanim()
motion = moveand_slide(motion)
func onVisibilityNotifier2Dscreenexited():
print("Player off screen")`