2D Metroidvania - 3 - Jump and double jump

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

ความคิดเห็น •

  • @jeanmakesgames
    @jeanmakesgames  10 หลายเดือนก่อน +6

    If you have issue with the player bouncing on the floor while continuing to press the space bar, after you code the player like mine just change "action_pressed" by "action_just_pressed", that will fix it! :)

  • @takemetotherift2095
    @takemetotherift2095 6 หลายเดือนก่อน +5

    for anyone struggling on this episode here is a revised script:
    extends CharacterBody2D
    var input = 0.0
    @export var speed = 100.0
    @export var gravity = 10
    # Variables for jumping
    var jump_count = 0
    @export var max_jump = 2
    @export var jump_force = 500
    # Called when the node enters the scene tree for the first time.
    func _ready():
    pass # Replace with function body.
    # Called every frame. 'delta' is the elapsed time since the previous frame.
    func _process(delta):
    movement(delta)
    func movement(delta):
    input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    if input != 0:
    velocity.x = input * speed
    if input > 0:
    $Sprite2D.scale.x = 1
    else:
    $Sprite2D.scale.x = -1
    $anim.play("walk")
    else:
    velocity.x = 0
    $anim.play("idle")
    # Code related to jumping
    if is_on_floor():
    jump_count = 0
    if Input.is_action_just_pressed("ui_accept") and jump_count < max_jump:
    jump_count += 1
    velocity.y = -jump_force
    if not is_on_floor():
    if velocity.y < 0:
    $anim.play("jump")
    else:
    $anim.play("fall")
    # Apply gravity
    velocity.y += gravity
    move_and_slide()

    • @MisterTopShelf_Nate
      @MisterTopShelf_Nate 3 หลายเดือนก่อน

      You, are a legend my good friend. This code worked perfectly and was so much more condensed and easy to adjust. My props to you!

  • @Ghostpants446
    @Ghostpants446 6 หลายเดือนก่อน

    ooo this is good i try to get ahead but on some cases like this i just did not know about things like the !is_on_floor stuff as well as where to play some code like the jump counter reset, still great tutorials so far! 👍

  • @goldenemperorofcurry
    @goldenemperorofcurry 3 หลายเดือนก่อน

    Great video. I'm having a problem, whenever I get to the part where I add ----&& jump_count < max_jump: ----for the double jump the line turns red and does not accept and says "Identifier jump_count not declared in current scope

    • @Hutchmink1988
      @Hutchmink1988 3 หลายเดือนก่อน

      Im also very new to coding but i beleave that you havent defined the variable jump_count. So basically missing "var jump_count = 0" or you have a typo in it.

  • @AirspaceSlayers
    @AirspaceSlayers 9 หลายเดือนก่อน +1

    At 6.02, if i launch the game i have a error that says: Invalid call. Nonexistend function 'Is_action_pressed' in base 'float'.
    What do i do???!

    • @AirspaceSlayers
      @AirspaceSlayers 9 หลายเดือนก่อน

      nevermind it works now

    • @jwithersooon
      @jwithersooon 8 หลายเดือนก่อน

      i did the same thing lol

  • @vinivini2651
    @vinivini2651 8 หลายเดือนก่อน

    Hello, I'm loving the tutorials, can you help me? For some reason my Player doesn't move from the platform with high gravity (10), so I keep trying with very low ones and it kind of gets stuck, you know. Has it ever happened to you?

  • @playmaker7871
    @playmaker7871 7 หลายเดือนก่อน

    Hello, I have an issue where my character only plays the first frame of the jump and fall animations
    I copied your code verbatim from the first video to here

    • @thamster55
      @thamster55 5 หลายเดือนก่อน

      Quite late, but did you check if looping is on for the animation?

  • @DragonFlyFinal
    @DragonFlyFinal 8 หลายเดือนก่อน +2

    Hi, my player isn't jumping. He keeps getting stuck on the ground and jitters when I press the jump key... I went back and forwards in the code, comparing with yours, I couldn't find a single thing that indicates a difference that may cause this problem...
    EDIT: It broke around 5:30, I continued coding because I thought it would be solved with the rest of the code, but it didin't...
    Here is my code:
    --------------------------
    extends CharacterBody2D
    # Variables
    var input
    @export var speed = 100.0
    @export var gravity = 10
    ## Variables for jumping
    var jump_count = 0
    @export var max_jump = 2
    @export var jump_force = 500
    func _ready() -> void:
    pass # Replace with function body.
    func _process(delta: float) -> void:
    input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")

    if input != 0:
    # Right
    if input > 0:
    velocity.x = velocity.x + (speed * delta)
    velocity.x = clamp(speed, 100.0, speed)
    $Sprite2D.scale.x = 1 # Flip to right
    $anim.play("Walk")
    # Left
    if input < 0:
    velocity.x = velocity.x + (-speed * delta)
    velocity.x = clamp(-speed, 100.0, -speed)
    $Sprite2D.scale.x = -1 # Flip to left
    $anim.play("Walk")

    if input == 0:
    velocity.x = 0
    $anim.play("Idle")

    if is_on_floor():
    jump_count = 0

    if !is_on_floor():
    if velocity.y < 0:
    $anim.play("Jump")
    if velocity.y > 0:
    $anim.play("Fall")

    if Input.is_action_pressed("ui_accept") && is_on_floor() && jump_count < max_jump:
    jump_count += 1
    velocity.y -= jump_force
    velocity.x = input
    if !is_on_floor() && Input.is_action_just_pressed("ui_accept") && jump_count < max_jump:
    jump_count += 1
    velocity.y -= jump_force * 1.2
    velocity.x = input
    if !is_on_floor() && Input.is_action_just_released("ui_accept") && jump_count < max_jump:
    velocity.y = gravity
    velocity.x = input
    else:
    gravity_force()

    gravity_force()
    move_and_slide()

    func gravity_force():
    velocity.y += gravity

    • @spelarnet
      @spelarnet 7 หลายเดือนก่อน +1

      same here.. did u solve it

    • @DragonFlyFinal
      @DragonFlyFinal 7 หลายเดือนก่อน +1

      @@spelarnet not yet, I moved on to watching other tutorials

    • @shivamsingh-hh1jp
      @shivamsingh-hh1jp 7 หลายเดือนก่อน

      # Code for jumping
      if is_on_floor():
      jump_count = 0

      if !is_on_floor():
      if velocity.y < 0:
      $AnimationPlayer.play("Jump")
      if velocity.y > 0:
      $AnimationPlayer.play("Fall")

      if Input.is_action_just_pressed("ui_accept") && is_on_floor() && jump_count < max_jump:
      jump_count += 1
      velocity.y -= jump_force
      velocity.x = input

      if !is_on_floor() && Input.is_action_just_pressed("ui_accept") && jump_count < max_jump:
      jump_count += 1
      velocity.y -= jump_force * 1.3
      velocity.y = clamp(-jump_force,-jump_force, 700)
      velocity.x = input
      else:
      gravitatioal_force()

      gravitatioal_force()
      move_and_slide()
      func gravitatioal_force():
      velocity.y += gravity
      Hi if you like you can use this code

    • @rootkitty1337
      @rootkitty1337 7 หลายเดือนก่อน

      @@DragonFlyFinal try this
      if Input.is_action_just_pressed("ui_accept"):
      if velocity.y

    • @tSaturn
      @tSaturn 6 หลายเดือนก่อน

      turn on v-sync in Godot project preferences! the_process function runs as many times as your computer can handle. turning on v-sync will make it run at your monitors refresh rate. you can also just replace _process with _physics_process which will lock it to the physics frame-rate also set in project preferences.

  • @shinkotsu6559
    @shinkotsu6559 10 หลายเดือนก่อน

    Tres bonne vidéo merci ! petite question, quand je laisse s^pace appuié je jump en boucle, c'est possible de bloquer ca et que je doive réappuier sur space sur initié le jump

    • @jeanmakesgames
      @jeanmakesgames  10 หลายเดือนก่อน +1

      Bonjour, et merci :) Oui c'est possible de desactiver le jump, il y a plein de maniere de faire, la plus simple est de mettre 'action_just_pressed' au lieu d'"action_pressed" (il me semblait l'avoir mis dans la vidéo mais je l'ai oublié, je vais le rajouter dans une future video sur le wall jump),.
      Mais il y a d'autre maniere de faire, par exemple creer une variable (par exemple "is_pressed" et compter le nombre de fois ou ca a était pressé (par exemple 2) et ensuite creer une condition pour etre sure que si la touche a déja était pressé on ne peut pas re-sauter tout de suite. Mais apres il faut pouvoir réinitialisé le saut d'une autre maniere. Une autre maniere de faire est de creer un timer qui apres un certain temps desactive la touche si elle est pressé trop longtemps (par exemple au dessus de 1 seconde), ca marchera aussi :)

  • @BrunoFernandes_84
    @BrunoFernandes_84 10 หลายเดือนก่อน

    very cool, are u going to implement random levels? cheers

    • @jeanmakesgames
      @jeanmakesgames  10 หลายเดือนก่อน +1

      Thank you! :) I've made some try with procedural generation and it works well, I just have issue with layering different part of the level in a way that is logical, so I don't fully know yet. Maybe in a simple form, or maybe in a more complete form but later on :)

    • @BrunoFernandes_84
      @BrunoFernandes_84 10 หลายเดือนก่อน

      @@jeanmakesgames nice will be very cool keep videos coming :) Cheers

  • @wash99
    @wash99 9 หลายเดือนก่อน

    my char keeps jumping for infinte times

  • @Yoni123
    @Yoni123 10 หลายเดือนก่อน

    How many episodes will this be?

  • @goldenstarsstudio3153
    @goldenstarsstudio3153 10 หลายเดือนก่อน

    Toujours un plaisir malgré le fait que je sois sur Godot 3.5 🤣🤣

    • @jeanmakesgames
      @jeanmakesgames  10 หลายเดือนก่อน

      Haha Godot 3 est toujours bon en meme temps! :)

    • @goldenstarsstudio3153
      @goldenstarsstudio3153 10 หลายเดือนก่อน

      @@jeanmakesgames enfin j'ai godot 4.1 sur mon pc mais je vois pas trop l'intérêt de tout rapprendre😔🤣

  • @TheSatyrical
    @TheSatyrical 6 หลายเดือนก่อน

    Here's my attempt at jumping logic:
    extends CharacterBody2D
    var input
    @export var speed = 150.0
    @export var gravity = 1000
    # variables for jumping
    var jump_count = 0
    @export var max_jump_count = 2
    @export var jump_force = 400
    @export var max_jump_height = 75
    var jump_timer = 0.0
    var is_jumping = false
    # Called when the node enters the scene tree for the first time.
    func _ready():
    pass # Replace with function body.
    # Called every frame. 'delta' is the elapsed time since the previous frame.
    func _process(delta):
    movement(delta)
    func movement(delta):
    input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")

    if input != 0:
    if input > 0:
    velocity.x += speed * delta
    velocity.x = clamp(speed, 150.0, speed)
    $Sprite2D.scale.x = 1
    $anim.play("Walk")
    if input < 0:
    velocity.x -= speed * delta
    velocity.x = clamp(-speed, -150.0, -speed)
    $Sprite2D.scale.x = -1
    $anim.play("Walk")

    if input == 0:
    velocity.x = 0
    $anim.play("Idle")

    if is_on_floor():
    jump_count = 0
    is_jumping = false
    if !is_on_floor():
    if velocity.y < 0:
    $anim.play("Jump")
    else:
    $anim.play("Fall")

    if Input.is_action_just_pressed("ui_accept") && jump_count < max_jump_count:
    jump_count += 1
    velocity.y = -jump_force
    jump_timer = 0.0
    is_jumping = true
    gravity_force(delta)
    move_and_slide()


    func gravity_force(delta):
    if not is_jumping:
    velocity.y += gravity * delta
    else:
    if jump_timer * jump_force < max_jump_height && Input.is_action_pressed("ui_accept"):
    jump_timer += delta
    else:
    velocity.y = velocity.y/3
    is_jumping = false

    • @andresfelipegomez1342
      @andresfelipegomez1342 2 หลายเดือนก่อน

      Your code is so cool, you fixed the error that occurs in the double when being close to the ground