Copied code not working

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

I’ve copied the code from another project. I used the same exact setup and now it doesn’t work, the character isn’t moving or doing anything. The code is below.

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const MAX_SPEED = 100
const JUMP_HEIGHT = -500
var motion = Vector2()

func _physics_process(delta):

motion.y += GRAVITY
var friction = false

if Input.is_action_pressed("ui_right"):
	motion.x += ACCELERATION
	motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
	$Sprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
	motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
	$Sprite.flip_h = true
	friction = true

if is_on_floor():
	if Input.is_action_just_pressed("ui_up"):
		motion.y = JUMP_HEIGHT
	if friction == true:	
		motion.x = lerp(motion.x, 0, 0.2)
	if friction == true:
		motion.x = lerp(motion.x, 0, 0.05)
motion = move_and_slide(motion, UP)


Are you using $AnimatedSprite?

Friends-Games | 2020-08-22 16:42

Yes and it still doesn’t work. Is it a bug?

JAA2000 | 2020-08-22 17:08

you have setup those animation in your animated sprite? “Jump”, “Idle”, and “Run”?

rakkarage | 2020-08-22 19:38

Yep, my character can’t even turn around let alone move. Maybe this is a bug.

JAA2000 | 2020-08-22 19:42

Can you upload an (if possible: minimal) example project? You’ll have to do that when reporting a bug on github anyways.

njamster | 2020-08-24 19:10