首页 > 解决方案 > 为什么这个变量在 gdscript 中不断变为 false?

问题描述

我正试图让这个脚本保持原状。当玩家跳跃时,它应该是地面并开始移动而不是停止。但是,它只有在玩家跳跃时才会移动。

我的代码:

extends Area2D

#Script-Purpose: move and delete ground

#Ground moving speed
const SPEED = -150

#a vector2 to change the speed of the ground
var velocity = Vector2()

#to check if you have jumped yet
var Jumped=false

#calls Physics
func _physics_process(delta):

        #left-click=jump
    if Input.is_action_pressed("ui_jump"):
        Jumped=true

    #make the velocity.x equal to speed accounted with delta time
    if Jumped==true:
        print(Jumped)
        velocity.x = SPEED * delta
        translate(velocity)
    else:
                #this is here so I can check if the Jumped var is false
        print(Jumped)

Jumped 有一半是假的,另一半是真的。

标签: godotgdscript

解决方案


推荐阅读