How to jump over platform step by step?

el_filipeel_filipe Posts: 3Member
edited May 15 in Programming

how to make jump from platform to platform like the game "Q*Bert's Qubes"?
At each keyboard entry, the player should move without interruption to a platform.
All platforms have the same width and spaced regularly (like a grid).
The player can also jump from 2 platforms at a time and can fall if there is no platform at his arrival. So each jump must have the same length. ex: 1 small jump move on 32px, and 1 long jump move on 64px.

A link to a video of "Q*Bert's Qubes":

And a code that doesnt work because the move can be interrupted at any time even with the yield() and set_process() functions.
If you press several times right/left button, the player jumps higher and higher and never fall (or jump down) And small jump size are wrong.

extends KinematicBody2D


const GRAVITY: int = 64
const SPEED: int = 150
const JUMP_HEIGHT: int = -64
const UP: Vector2 = Vector2(32, -1)

var _motion: Vector2 = Vector2()

func _ready():

func _physics_process(delta):
    var move = MOVES.NONE

    if Input.is_action_pressed("ui_left"):
        move = MOVES.LEFT
    elif Input.is_action_pressed("ui_right"):
        move = MOVES.RIGHT


func move_to(move: int):
    _motion.y += GRAVITY

    var anim: String = "idle"


    match move:
            anim = "jump_short"
            _motion.y = JUMP_HEIGHT
            _motion.x = -SPEED
            anim = "jump_short"
            _motion.y = JUMP_HEIGHT
            _motion.x = SPEED
            _motion.x = 0

    $ #duration of "jump_short" = 0.7 sec
    _motion = move_and_slide(_motion, UP)

    yield($Anim, "animation_finished")


Thank you for your solutions!

Tags :


  • SchorschSchorsch Posts: 51Member

    I don't get your problem? That you can change the direction while the player is jumping? You can save the current state of the player and only trigger the jump if the key is hit, and the player is able to jump. So you have to move your "move" variable out of the process function. Then you have to check if move equals NONE and a jump-key is pressed. If the player lands, you have to set move back to NONE. Is that what you wanted?

  • el_filipeel_filipe Posts: 3Member

    I apologize, I misspoke.
    The character move only by bounce. And can bounce in 7 directions (see num MOVES{} in code).
    When we press a key, for example the right arrow key:
    The character makes a bounce to the platform on the right. As long as the player has not landed, no another movement are possible.
    It's only when it reaches a platform that we can move again the character.

Sign In or Register to comment.