可以在Godot中移动Kinematicbody2d

发布于 2025-02-12 17:42:45 字数 243 浏览 1 评论 0原文

我是Godot的新手,正在尝试将Kinematicbody2D沿X轴移动,但我无法做到。这是代码:

extends KinematicBody2D
func _physics_process(delta): 
    var velocity=Vector2(300, 0)
    move_and_slide(velocity)

我认为此功能(_PHYSICS_PROCESS)并未以某种方式调用或触发。

I am new to Godot and am trying to move a KinematicBody2D along the x axis, but I am not being able to. Here is the code:

extends KinematicBody2D
func _physics_process(delta): 
    var velocity=Vector2(300, 0)
    move_and_slide(velocity)

I think that this function(_physics_process) is not being called or triggered somehow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘴硬脾气大 2025-02-19 17:42:45

我正在使用Godot 2.7。这是问题吗?

在Godot 2中,我们有_Process_fixed_process,因此要做的第一件事是将_PHYSICS_PROCESS更改为_FIXED_FIXED_PROCESS

其次,默认情况下不启用它。因此,您应该调用set_fixed_process(true)启用它。像这样:

extends KinematicBody2D


func _ready():
    set_fixed_process(true)


func _fixed_process(delta): 
    var velocity=Vector2(300, 0)
    move_and_slide(velocity)

I am using Godot 2.7. Is that the problem?

In Godot 2 we had _process and _fixed_process, so the first thing to do is to change _physics_process to _fixed_process.

And second, it is not enabled by default. So you should call set_fixed_process(true) to enable it. Like this:

extends KinematicBody2D


func _ready():
    set_fixed_process(true)


func _fixed_process(delta): 
    var velocity=Vector2(300, 0)
    move_and_slide(velocity)
李不 2025-02-19 17:42:45

也许下一个可以帮助您:

  • 确保将脚本附加到运动学体体上。
  • 检查检查员中的Kinematicbody2d的物理 sync 已禁用。
  • 检查您的脚本中没有set_physics_process(false),或者对Kinematic脚本执行此操作。

Maybe the next can help you:

  • Make sure the script is attached to the kinematicbody.
  • Check the property sync to physics of KinematicBody2D in the inspector is disabled.
  • Check that you don't have set_physics_process(false) inside your script or another one that do this to the kinematic script.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文