Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | kelnosh |
Hi!
I’m trying to make a grid-based movement game but when character jumps, it’s affected by gravity; too, the character doesn’t receive instructions by the keyboard, but it receive instructions step by step when the players push “GO” button
I have the gravity affecting the character, but I don’t know how to move the character step by step on grid-based movement. Someone has an idea or some video tutorial
The var “moviendose” is changed to true when the player press GO
extends KinematicBody2D
var moviendose = false
var lista_habilidades_jugador = []
onready var tweene = $AnimatedSprite
const GRAVITY = 9.8
var velocity = Vector2.ZERO
const def_habilidades = {
"Habilidad1": Vector2(16,0),
"Habilidad2": Vector2(-16,0),
"Habilidad3": Vector2(0,(-GRAVITY*16))
}
func _physics_process(delta):
velocity.y += GRAVITY
if lista_habilidades_jugador.size() == 0:
moviendose = false
if moviendose == true:
movimiento()
velocity = move_and_slide(velocity)
func movimiento():
for mov in lista_habilidades_jugador:
if mov == "Habilidad1":
velocity = velocity.move_toward(def_habilidades[mov] , 5)
tweene.flip_h = false
tweene.play("correr")
if mov == "Habilidad2":
velocity = lerp(velocity + def_habilidades[mov], Vector2.ZERO,20)
tweene.flip_h = true
if mov == "Habilidad3":
velocity = velocity + def_habilidades[mov]
self.lista_habilidades_jugador.pop_front()