extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2.ZERO
var state_machine
func ready():
statemachine = $AnimationTree.get("parameters/playback")
func getinput():
var current = statemachine.getcurrentnode()
velocity = Vector2.ZERO
if Input.isactionpressed("right"):
velocity.x += 1
statemachine.travel("RunRight")
if Input.isactionpressed("left"):
velocity.x -= 1
statemachine.travel("RunLeft")
if Input.isactionpressed("up"):
velocity.y -= 1
statemachine.travel("RunUp")
if Input.isactionpressed("down"):
velocity.y += 1
statemachine.travel("RunDown")
if velocity.length() == 0:
state_machine.travel("IdleDown")
func physicsprocess(delta):
getinput()
velocity = velocity.normalized() * speed
velocity = moveand_slide(velocity)