Why isn't my character moving?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By K1ngK0ng

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 get_input():
var current = state_machine.get_current_node()
velocity = Vector2.ZERO
if Input.is_action_pressed(“right”):
velocity.x += 1
if Input.is_action_pressed(“left”):
velocity.x -= 1
if Input.is_action_pressed(“up”):
velocity.y -= 1
if Input.is_action_pressed(“down”):
velocity.y += 1
if velocity.length() == 0:

func _physics_process(delta):
velocity = move_and_slide(velocity)

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

figroot | 2021-11-04 18:18

:bust_in_silhouette: Reply From: timothybrentwood

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.

now my character is moving but no animations are playing

K1ngK0ng | 2021-11-04 17:38

:bust_in_silhouette: Reply From: K1ngK0ng

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