How do I make my character stop moving after i stop pressing the button?
my code is below:
extends KinematicBody2D
const UP = Vector2(0, -1)
const SPEED = 125
const MAX_SPEED = 125
const GRAVITY = 20
const FRICTION = 0.1
const JUMP_HEIGHT = 500
const MAX_JUMP_HEIGHT = 1000
const JUMPS = 3
var motion = Vector2()
var jumps_available := JUMPS
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("right"):
motion.x += SPEED
motion.x = min(motion.x+SPEED, MAX_SPEED)
motion.x = lerp(motion.x, 0, FRICTION)
elif Input.is_action_pressed("left"):
motion.x -= SPEED
motion.x = max(motion.x-SPEED, -MAX_SPEED)
motion.x = lerp(motion.x, 0, FRICTION)
# _physics_process
if Input.is_action_just_pressed("jump") and jumps_available > 0:
motion.y -= JUMP_HEIGHT
motion.y = max(motion.x-JUMP_HEIGHT, -MAX_JUMP_HEIGHT)
jumps_available -= 1
# _physics_process
if is_on_floor():
jumps_available = 2
motion = move_and_slide(motion, UP)