Hello
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": https://youtu.be/Pwr99PGyxV0
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
enum MOVES { NONE=0, LEFT, RIGHT, DOWN, UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT }
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():
pass
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
move_to(move)
func move_to(move: int):
_motion.y += GRAVITY
var anim: String = "idle"
set_process(false)
match move:
MOVES.LEFT:
anim = "jump_short"
_motion.y = JUMP_HEIGHT
_motion.x = -SPEED
MOVES.RIGHT:
anim = "jump_short"
_motion.y = JUMP_HEIGHT
_motion.x = SPEED
_:
_motion.x = 0
$Anim.play(anim) #duration of "jump_short" = 0.7 sec
_motion = move_and_slide(_motion, UP)
yield($Anim, "animation_finished")
set_process(true)
Thank you for your solutions!