невозможно добавить функцию времени койота

Я хочу добавить время койота в свой 2D-платформер в godot, но мне не удалось заставить его работать. вот мой код, я выучил GDscript 2 недели назад и я ни в коем случае не эксперт ошибка или что-то, что можно исправить, я бы хотел прочитать это, даже если это не о времени койота. расширяет KinematicBody2D

      const UP = Vector2(0,-1)
const GRAVITY = 9
const SPEED = 150
const JUMP_HEIGHT = -400

var motion = Vector2()
var coyote_time
var is_jumping = false
var was_on_floor = is_on_floor()

func _ready():
    coyote_time = Timer.new()
    coyote_time.one_shot = true
    coyote_time.wait_time = 2.0
    add_child(coyote_time)
    $AnimationTree.active = true

func _physics_process(delta):
    motion.y += GRAVITY
    if Input.is_action_pressed("move_right"):
        motion.x = SPEED
        $Sprite.flip_h = false
        $AnimationTree.set("parameters/state/current", 1)
    elif Input.is_action_pressed("move_left"):
        motion.x = -SPEED
        $Sprite.flip_h = true
        $AnimationTree.set("parameters/state/current", 1)
    else:
        motion.x = 0
        $AnimationTree.set("parameters/state/current", 0)
    if coyote_time.is_stopped():
     motion.y += GRAVITY

    if is_on_floor():
        is_jumping = false
        if Input.is_action_just_pressed("jump"):
            is_jumping = true
            motion.y = JUMP_HEIGHT
    elif not is_on_floor() and was_on_floor and not is_jumping and Input.is_action_just_pressed("jump"):
            coyote_time.start()
            is_jumping = true
            motion.y = JUMP_HEIGHT
        
    else:
        if motion.y < 0:
            $AnimationTree.set("parameters/state/current", 2)
        else:
            $AnimationTree.set("parameters/state/current", 3)
    
    
    motion = move_and_slide(motion, Vector2.UP)
    pass

0 ответов

Другие вопросы по тегам