我知道这可能是一个小众问题,但我试图了解如何使用 Python 在 Godot 中工作。我使用的是 PythonScript 库版本 0.5,并且有以下代码:
from godot import exposed, export
from godot import *
@exposed
class Node2D(KinematicBody2D):
speed = 50
def _physics_process(self,delta):
velocity = Vector2.ZERO
if Input.is_action_pressed('ui_up') == True:
velocity.y -= 1*speed
if Input.is_action_pressed('ui_down') == True:
velocity.y += 1*speed
move_and_slide(velocity)
Run Code Online (Sandbox Code Playgroud)
在当前状态下,当我运行它时,它会抛出“NameError:名称'move_and_slide'未定义”,尽管move_and_slide在KinematicBody2D方法中明确列出。
预先非常感谢您的反馈,如果我可以进一步澄清这个问题,请告诉我。
我确实发现了这个问题!我需要添加一个自我。在 self.move_and_slide() 前面。正确代码如下:
from godot import exposed, export
from godot import *
@exposed
class Node2D(KinematicBody2D):
def _physics_process(self,delta):
speed = 50
velocity = Vector2.ZERO
if Input.is_action_pressed('ui_up') == True:
velocity.y -= 1*speed
if Input.is_action_pressed('ui_down') == True:
velocity.y += 1*speed
self.move_and_slide(velocity)
Run Code Online (Sandbox Code Playgroud)
我还需要在物理处理函数中移动速度,目前我还不能 100% 确定为什么它没有被外部注意到。
| 归档时间: |
|
| 查看次数: |
1727 次 |
| 最近记录: |