How to Double Jump in Godot 4

Sdílet
Vložit
  • čas přidán 22. 08. 2024
  • So you've got a platform controller and now you want to be able to double jump?
    Watch this video to see how.
    You might need to integrate it with your other code but it's much easier than it seems if you understand what is going on.
    Enjoy!

Komentáře • 47

  • @goncalocascais
    @goncalocascais Před 3 měsíci +12

    As some one who is learning how to code, its so hilarious how easy it is to double jump after seeing this video. I think the biggest help this video gave me was that I should start thinking outside the box and have that Programmer mentality that I am clearly missing. Thanks a lot mate!
    PS: Just made a small improvement to the code so you are not allowed to double jump if you drop out of a ledge (it will only allow you to jump one time)
    #Single jump if you drop off a ledge
    if Input.is_action_just_pressed("jump") and not is_on_floor() and jump_count < max_jumps:
    velocity.y = JUMP_VELOCITY
    jump_count += 2

    #Double jump.
    if Input.is_action_just_pressed("jump") and jump_count < max_jumps:
    velocity.y = JUMP_VELOCITY
    jump_count += 1
    if is_on_floor():
    jump_count = 0

    • @AdolfHitler-lk4vo
      @AdolfHitler-lk4vo Před 12 dny

      also put velocity.y = 0 at the top for double jump so that it resets your falling speed

  • @Kloetee
    @Kloetee Před měsícem +1

    And here I was racking my brain with bool variables and how to properly set them and creating for loops to constantly check and in the end its this simple? I really have a lot to learn still...
    Thanks for this humbling but teaching experience!

  • @ebhamlin3618
    @ebhamlin3618 Před 4 měsíci +1

    Seriously- thank you SO much for this tutorial!!! I just started my first platformer last week and this was the only tutorial that helped me with this function! Thank you!!!

  • @Epsio0
    @Epsio0 Před 3 měsíci +2

    That is a lot simpler than what I was doing with a bool. Thanks

  • @ZexyAdventures
    @ZexyAdventures Před měsícem +1

    Works perfectly with 3d games too!

  • @MattHendersonRoastinCoffee
    @MattHendersonRoastinCoffee Před měsícem +1

    Awesome tutorial!!

  • @RAFLAMOLAO
    @RAFLAMOLAO Před 6 měsíci

    wow ive been trying to figure this one out and I was really close! haha! Thanks! It was a lot simpler than i thought.

  • @mathislalonde353
    @mathislalonde353 Před měsícem

    Hi !
    Nice tuto but I don't know why I can have infinite double jump... so there is my code (i have a dash too) :
    extends CharacterBody2D
    @export var speed = 300
    @export var gravity = 30
    @export var jump_force = 800
    @export var dash_speed = 900
    var dashing = false
    var can_dash = true
    var jump_count = 0
    var max_jumps = 2
    func _physics_process(delta):
    if !is_on_floor():
    jump_count = 0
    velocity.y += gravity
    if velocity.y > 1000:
    velocity.y = 1000

    if Input.is_action_just_pressed("jump"):
    if jump_count < max_jumps:
    velocity.y = -jump_force
    jump_count += 1

    var horizontal_direction = Input.get_axis("move_left","move_right")
    velocity.x = speed * horizontal_direction

    if horizontal_direction:
    if dashing:
    velocity.x = dash_speed * horizontal_direction


    if Input.is_action_just_pressed("dash") and can_dash:
    dashing = true
    can_dash = false
    $dash_timer.start()
    $dash_again_timer.start()


    move_and_slide()
    func _on_dash_timer_timeout():
    dashing = false
    func _on_dash_again_timer_timeout():
    can_dash = true

    • @SRCoder
      @SRCoder  Před měsícem

      @mathislalonde353 make sure you've connected the tier to the jump timer timeout function

  • @GeneralChrisGaming
    @GeneralChrisGaming Před 2 měsíci

    For 3d got to add something for when they player steps off a ledge so they only have 1 jump being their double jump hmmmm

  • @05374
    @05374 Před měsícem

    Very helpful

  • @jambreadd
    @jambreadd Před 3 měsíci

    thanks it worked.

  • @henuog9473
    @henuog9473 Před 7 měsíci

    Thanks this was very helpful 👍

  • @kjbaran
    @kjbaran Před 7 měsíci +1

    worked for me, thank you

  • @sethbozeman229
    @sethbozeman229 Před 8 měsíci +2

    thanks so much!!!

  • @ameerachannel1667
    @ameerachannel1667 Před 3 měsíci

    this is the exact thing i did in javascript but it didnt work perfectly, sometimes it jump, sometimes did not.

  • @W4CKYYY
    @W4CKYYY Před 3 měsíci

    How can I add my animation to it?

  • @pastellepuppy
    @pastellepuppy Před 6 měsíci

    The only problem with this is that falling off of a ledge allows you to jump twice.

    • @SRCoder
      @SRCoder  Před 6 měsíci +1

      Yes but it's not bad for a five minute tutorial aimed at beginners! Have fun tweaking it to try to fix your issue. That's part of the fun!!

  • @mr_grey555
    @mr_grey555 Před 4 měsíci

    OMG. Thanks you so much❤

  • @SGI077
    @SGI077 Před 3 měsíci

    legend!

  • @PumaVoid
    @PumaVoid Před 3 měsíci

    W tutorial

  • @madlink3495
    @madlink3495 Před 6 měsíci

    thank you for this. is there a way to change it in an area 2d?
    In my project I want my player to double jump outside of water, but I have a block where I want jumping to be infinite but only inside it. I've gotten it to change gravity inside it, but it still treats the player on the floor so the jumps are still limited. Can you help me?

  • @scarvvv
    @scarvvv Před 8 měsíci +1

    BRO HOW TO STRONG DOUBLE JUMP BRO???

    • @SRCoder
      @SRCoder  Před 8 měsíci +1

      What do you mean? The jump force is just a variable that you can change. And because you are "counting" the jumps with a different variable, you could change the jump force however or whenever you want.

    • @scarvvv
      @scarvvv Před 8 měsíci

      @@SRCoder BRO I am a beginner

    • @SRCoder
      @SRCoder  Před 8 měsíci

      @@scarvvv but what do you mean by a "strong" double jump?

    • @harmoen
      @harmoen Před 7 měsíci +3

      BRO I think YOU need to go back and review the basics

    • @tomasalves3462
      @tomasalves3462 Před 5 měsíci +1

      if jump_count >= 2:
      velocity.y = JUMP_VELOCITY - 300

  • @DazDroAnimations
    @DazDroAnimations Před měsícem

    2:37

  • @BoltSwitch_
    @BoltSwitch_ Před 3 měsíci

    how could i make a double jump animation

    • @BoltSwitch_
      @BoltSwitch_ Před 3 měsíci

      nvm, did it

    • @BoltSwitch_
      @BoltSwitch_ Před 3 měsíci +1

      if jump_count == 2:
      new_animation = &"DoubleJump"

    • @SRCoder
      @SRCoder  Před 3 měsíci +1

      Isn't programming easy!

  • @iliveunderarock8070
    @iliveunderarock8070 Před 3 měsíci

    whenever i jump twice i cant jump any more do you know what i did wrong

  • @M2Entretenimento
    @M2Entretenimento Před 8 měsíci +1

    Incrível!

  • @marco4237
    @marco4237 Před 8 měsíci

    Thnks for avor

  • @Nori28844
    @Nori28844 Před 6 měsíci

    pleas C# cod😫😫😫😫😫😫😫😫

    • @SRCoder
      @SRCoder  Před 6 měsíci +1

      Why? The Beaty of godot is that its simple. Why make it harder by using c#?

    • @pastellepuppy
      @pastellepuppy Před 6 měsíci +2

      @@SRCoder It tends to perform better and makes porting from Unity easier. I don't think you should feel pressed to make a tutorial for C# if you don't want to tho