![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Lucky_Mouse |
Goodnight, I’m learning GDscript and I make a personal challenge to code a double jump for my character, I made it but it feels a little slow sometimes and sometimes doesn´t work, this is the Script I make please tell me if there is something to improve:
<extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 20
const SPEED = 200
const JUMP_HEIGHT = -500
const MAX_JUMP_COUNT = 2
var second_jump = false
var jump_count = 0
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
$AnimatedSprite.play("correr")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
$AnimatedSprite.play("correr")
$AnimatedSprite.flip_h = true
else:
motion.x = 0
$AnimatedSprite.play("quieto")
if is_on_floor():
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_HEIGHT
jump_count = 1
motion = move_and_slide(motion, UP)
if second_jump:
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_HEIGHT
jump_count = 2
if jump_count < MAX_JUMP_COUNT:
second_jump = true
else:
second_jump = false>