I'm thinking the way to jump twice and jump height at the same time, works fine but for some reason I can again jump endlessly. Is there a viable solution?

const UP = Vector2(0, -1)
var motion = Vector2()
export var speed = 300
export var gravity = 20
export var jumpforce = -400
export var extra
jump = 1
var jumpcount = 0
func _physics
process(delta):
motion.y += gravity
if Input.is
actionpressed("uiright"):
motion.x = speed

elif Input.is_action_pressed("ui_left"):
motion.x = -speed

else:
motion.x = 0

if is_on_floor():
jump_count = 0
if Input.is_action_just_pressed("ui_up"):
motion.y = jump_force
elif (jump_count == 1):
if Input.is_action_just_pressed("ui_up"):
motion.y = jump_force
jump_count = 0
if Input.is_action_just_released("ui_up") and jump_count == 0:
motion.y = 0
motion = move_and_slide(motion, UP)
in Engine

–1 vote

extends KinematicBody2D
classname Strengthdemon
const UP = Vector2(0, -1)
var motion = Vector2()
export var speed = 300
export var gravity = 20
export var jumpforce = -400
export var extra
jump = 2
var jump_count = 0

## Basic movement

func physicsprocess(delta):
motion.y += gravity
if Input.isactionpressed("ui_right"):
motion.x = speed

elif Input.is_action_pressed("ui_left"):
motion.x = -speed

else:
motion.x = 0

## Jump

if is_on_floor():
jump_count = 0
if Input.is_action_just_pressed("ui_up") and jump_count <= extra_jump:
motion.y = jump_force
jump_count += 1
if Input.is_action_just_released("ui_up") and jump_count == 0:
motion.y = 0
motion = move_and_slide(motion, UP)
by (17 points)
+1 vote

you should check if cont == 0 in the first if where you check if ui_up is pressed... otherwise you will end up entering that if always you press that button. Also, if after the second jump, you set jump_count to 0 aggain, you will be able to keep jumping.. Try something like

if is_on_floor():
jump_count = 0
if  jump_count == 0 and Input.is_action_just_pressed("ui_up"):
motion.y = jump_force
jump_count = 1
elif (jump_count == 1):
if Input.is_action_just_pressed("ui_up"):
motion.y = jump_force
jump_count = 2
if Input.is_action_just_released("ui_up") and motion.y < 0:
motion.y = 0
motion.y += 980*delta
motion = move_and_slide(motion, Vector2.UP)
by (3,491 points)

Yes, im sure.. im trying it right now.. Of course, it wont move because i just coded the jump, as that was what was aksed in the question.

Also, check that ive added gravity and jump force myself because it was not provided. Maybe youll need to tweak those values.

Okey, Let me try

Problem sloved, thanks for the help bro.

no problem! if the answer helped, you may select it so others see its solved.