0 votes

Hi, I'm working on a 2d platformer. I want for the player to stop moving up when the player releases the jump button.

This is the code

extends KinematicBody2D

var motion = Vector2()
var airjump = 0.2
var airtime = 0.2
const MOE = 0.2
const CTIME = 0.2
const SPEED = 300
const GRAVITY = 60
const JUMPHEIGHT = -700
const UP = Vector2(0,-1)

#move right and left whenthe arrow keys are presed
func _physics_process(delta):
    motion.y += GRAVITY
    if Input.is_action_pressed("ui_right"):
        motion.x = SPEED
    elif Input.is_action_pressed("ui_left"):
        motion.x = -SPEED
        motion.x = 0

    #Timer to dimtermine if the player inputed the jump button recently
    airjump -= get_process_delta_time()
    if Input.is_action_just_pressed("ui_up"):
        airjump = CTIME
    #Timer to see if the player was on the floor recently
    airtime -= get_process_delta_time()
    if is_on_floor():
        airtime = MOE

    #Tells the game to jump if both timers are good with jumping
    if airjump > 0 && airtime > 0:
            motion.y = JUMPHEIGHT

    #Make the player stop moving upwards when the jump button is released
    if Input.is_action_just_released("ui_up"):
        if motion.y > 0:
            motion.y * CUTJUMPHEIGHT

    motion = move_and_slide(motion, UP)
in Engine by (27 points)
edited by

motion.y += JUMPHEIGHT has been changed to motion.y = JUMPHEIGHT

Then maybe you should edit your question to avoid confusion.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.