hello i was wondering how to fix this code. The problem is that when i press left and right on the ground it doesnt work but my game has slopes and it only plays run animation on the slopes:
extends KinematicBody2D
#Player variables
const UP = Vector2(0, -1)
const GRAVITY = 8
const SPEED = 80
const JUMP_HEIGHT = -235
var motion = Vector2()
var on_ground = false
func _physics_process(delta):
#PlayerMovement
if Input.is_action_pressed("playerright"):
motion.x = SPEED
$Body.play("Run")
$Body.flip_h = false
elif Input.is_action_pressed("playerleft"):
motion.x = -SPEED
$Body.play("Run")
$Body.flip_h = true
else:
motion.x = 0
if on_ground == true:
$Body.play("Idle")
#PlayerJump
if Input.is_action_just_pressed ("playerjump"):
if on_ground ==true:
motion.y = JUMP_HEIGHT
on_ground = false
motion.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false
if motion.y <0:
$Body.play("Jump")
else:
$Body.play("Fall")
motion = move_and_slide(motion, UP)
pass
if someone could help i would be grateful thanks :)