0 votes

This is my script

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 = move
and_slide(velocity)

Godot version latest
in Engine by (27 points)

Are you receiving any error messages? Also, have you checked to make sure the input map is set up properly?

2 Answers

+1 vote

Every physics frame you reset the velocity to zero and only ever increment it by 1 in any direction then you feed that velocity into move_and_slide() then on the next frame you're resetting your velocity back to 0. It's likely that you're moving but very slowly at about 1 pixel per second.

You need to incorporate your speed variable into this by adding:

velocity = velocity.normalized() * speed

to the bottom of your get_input() function. Doing so should fix your problem.

by (3,707 points)

now my character is moving but no animations are playing

0 votes

lol my bad i dint have a start animation

But how would i cause my sprite to face the way i run when playing idle
rn its only playing a down facing idle i have a right a left and a up idle

by (27 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.