我知道这可能是一个利基问题,但我正在尝试理解如何使用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)在当前状态下,当我运行此状态时,它会抛出"NameError: name‘move_and_slide“,尽管move_and_slide在KinematicBody2D方法中有明确的列表。
谢谢你的反馈,如果我能进一步澄清这个问题,请告诉我。
发布于 2022-08-24 11:30:57
其实我发现了问题!我需要增加一个自我。在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)我还需要在physics_process函数中移动速度,目前我还不能100%确定为什么在外部没有注意到它。
https://stackoverflow.com/questions/73472016
复制相似问题