0 votes

extends KinematicBody2D

export (int) var speed = 200

var velocity = Vector2.ZERO
var state_machine

func ready():
state
machine = $AnimationTree.get("parameters/playback")

func getinput():
var current = state
machine.getcurrentnode()
velocity = Vector2.ZERO
if Input.isactionpressed("right"):
velocity.x += 1
statemachine.travel("RunRight")
if Input.is
actionpressed("left"):
velocity.x -= 1
state
machine.travel("RunLeft")
if Input.isactionpressed("up"):
velocity.y -= 1
statemachine.travel("RunUp")
if Input.is
actionpressed("down"):
velocity.y += 1
state
machine.travel("RunDown")
if velocity.length() == 0:
state_machine.travel("IdleDown")

func physicsprocess(delta):
getinput()
velocity = velocity.normalized() * speed
velocity = move
and_slide(velocity)

Godot version latest
in Engine by (27 points)

Few tips:
You can format your code in the question by selecting it and pressing the { } button above the text editor. This way others won't have problem reading it and you'll get the answer faster.
Also it's better to specify an exact version instead of "latest", since latest could mean latest stable release, in development build or something else entirely - also if somebody has the same question few years from now, they'll have even harder time pinpointing if the answer is suitable for their version of godot.

1 Answer

0 votes

This could possibly be the issue, from the docs:

The state machine must be running before you can travel. Make sure to either call start() or choose a node to Autoplay on Load.

by (402 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.