- Edited
So,I'm making a 2D platformer and I need the player to be able to float, or like, slowly descent to the ground, after doing a double jump and holding the up key, the double jump and walk are already done, but I just can't figure out a way to do the floating thing. Sorry if this is simple, I'm a big noob at programming.
My code so far:
const UP = Vector2(0, -1)
var motion = Vector2()
const GRAVITY = 20
const SPEED = 200
const JUMP_HEIGHT = -400
var double_jump = false
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
$Sprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
$Sprite.flip_h = true
else:
motion.x = 0
if is_on_floor():
double_jump = true
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_HEIGHT
elif Input.is_action_just_released("ui_up") and motion.y < 0:
motion.y *= 0.5
if double_jump and Input.is_action_just_pressed("ui_up") and not is_on_floor():
motion.y = JUMP_HEIGHT
double_jump = false
motion = move_and_slide(motion, UP)
pass