I think I might have screwed up and odds are it is something simple. I am fairly new to code but have been watching videos and reading tutorials. With this in mind I think something is off as my walk animations are working but my idle animations is only ever in one direction. If left is there it is always left regardless to order I place them in. If I remove left then it switches to another. They all work but I have to disable the rest. Any help is appreciated.
extends KinematicBody2D
export var speed = 200
export var motion_speed = 200
const idle_speed = 10
var raynode
var PlayerAnimNode
var anim = ""
var animnew = ""
onready var sprite = get_node("sprite")
var vel = Vector2()
func _ready():
set_fixed_process(true)
set_pos(Vector2(500, 300))
raynode = get_node("RayCast2D")
PlayerAnimNode = get_node("sprite")
func _fixed_process(delta):
var motion = Vector2()
if (Input.is_action_pressed("ui_right")):
motion += Vector2(1, 0)
raynode.set_rotd(90)
if (Input.is_action_pressed("ui_left")):
motion += Vector2(-1, 0)
raynode.set_rotd(270)
if (Input.is_action_pressed("ui_down")):
motion += Vector2(0, 1)
raynode.set_rotd(0)
if (Input.is_action_pressed("ui_up")):
motion += Vector2(0, -1)
raynode.set_rotd(180)
motion = motion.normalized()*motion_speed*delta
move(motion)
# set animation
if (motion.length() > idle_speed*0.09):
if (Input.is_action_pressed("ui_up")):
anim = "walk_up"
if (Input.is_action_pressed("ui_down")):
anim = "walk_down"
if (Input.is_action_pressed("ui_left")):
anim = "walk_left"
if (Input.is_action_pressed("ui_right")):
anim = "walk_right"
else:
if (raynode.get_rotd() == 180):
anim = "idle_up"
if (raynode.get_rotd() == 0):
anim = "idle_down"
if (raynode.get_rotd() == 270):
anim = "idle_left"
if (raynode.get_rotd() == 90):
anim = "idle_right"
if anim != animnew:
animnew = anim
PlayerAnimNode.play(anim)