This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 by (17 points)

2 Answers

–1 vote
Best answer

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,505 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.

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 Frequently asked questions and 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 [email protected] with your username.