Humanoid:MoveTo() 不起作用 |罗布乐思LUA

发布于 2025-01-18 01:11:43 字数 423 浏览 0 评论 0原文

因此,我正在尝试制作一个移动到地图中某个点的机器人 这是我的代码:

local character = script.Parent
local humanoid = character.Humanoid
local testpoint = character.Parent.Points["End Part 2"].Position

humanoid:MoveTo(testpoint)
humanoid.MoveToFinished:Connect(function()
    print("Reached Dest")
end)

当我启动游戏时,虚拟模型根本不会移动(即使Walltopoint已正确设置) 然后几秒钟后,消息到达了控制台中的dest打印,但人类机体没有移动。 我不知道为什么会发生这种情况,请您帮助我。 太感谢了。

So i'm trying to make a little bot that moves to a point in the map
Here is my code :

local character = script.Parent
local humanoid = character.Humanoid
local testpoint = character.Parent.Points["End Part 2"].Position

humanoid:MoveTo(testpoint)
humanoid.MoveToFinished:Connect(function()
    print("Reached Dest")
end)

when i launch the game, the dummy model doesn't move at all (even if WalkToPoint have been correctly set)
and then after a few seconds the message Reached Dest prints in the console but the humanoid hasn't move.
I have no idea why this happend, could you please help me.
Thank you so much.

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

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

发布评论

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

评论(3

垂暮老矣 2025-01-25 01:11:43

我以前曾经看到过尝试将实例属性存储在变量中的问题。您应该尝试:

local character = script.Parent
local humanoid = character.Humanoid
local testpoint = character.Parent.Points["End Part 2"]

humanoid:MoveTo(testpoint.Position)
humanoid.MoveToFinished:Connect(function()
    print("Reached Dest")
end)

另外,请确保您正确地获得了以前的变量,例如targuehumanoid

I have seen problems before with trying to store an instances attribute in a variables. You should try:

local character = script.Parent
local humanoid = character.Humanoid
local testpoint = character.Parent.Points["End Part 2"]

humanoid:MoveTo(testpoint.Position)
humanoid.MoveToFinished:Connect(function()
    print("Reached Dest")
end)

Also please make sure you are getting the previous variables correctly like character and humanoid

硪扪都還晓 2025-01-25 01:11:43

您可能需要考虑以下几件事:
首先,您需要确保人形机器人所在的模型中的所有部件都未锚定,因为否则它不会移动,即使它会像您一样触发“MoveToFinished”。

第二个是,目前 Roblox 似乎存在问题,因为在这种情况下使用您自己定义的 Vector3 几乎是不可能的,因为人形机器人不会移动到该位置,而是移动到大约 5-10 个螺柱之外。我遇到了这个问题,我通过使用任意“末端部分”(您可以使其不可见并关闭 CanCollide)来修复它,然后告诉我的人形机器人移动到该部分的位置而不是直接创建 Vector3。我希望这有帮助!

There are a few things that you might want to consider:
The first is that you need to make sure that all of the parts in the model that the humanoid is in are unanchored, because otherwise it will not move even though it will trigger "MoveToFinished" like it did for you.

The second is that there currently seems to be an issue with Roblox, as working with Vector3s that you have defined yourself in this situation can be near impossible because the humanoid will not move to the position, but rather about 5-10 studs away. I had this problem and I fixed it by using an arbitrary "end-part" (you can make this invisible and turn CanCollide off), and then telling my humanoid to move to this part's position instead of directly creating the Vector3. I hope this helps!

诠释孤独 2025-01-25 01:11:43

人形机器人:移动到(测试点)

除了我下面所说的之外,testpoint 没有设置为 Vector,这最终会把事情弄乱。一个可能的解决方案可能是:

humanoid:MoveTo(Vector3.new(testpoint))

但是,您不需要使用 MoveTo,我认为您可以同样轻松地使用 .Position,如果您这样做:

local character = script.Parent
local Torso = -- Get Torso somehow depending on your game rig
local pointToMove = character.Parent.Points["End Part 2"].Position
Torso.Position = Vector3.new(pointToMove)

humanoid:MoveTo(testpoint)

Aside from what I said below, testpoint is not set as a Vector, which ends up messing stuff up. A possible solution could be:

humanoid:MoveTo(Vector3.new(testpoint))

HOWEVER, You don't need to use MoveTo, I think you can use .Position just as easily, if you do this:

local character = script.Parent
local Torso = -- Get Torso somehow depending on your game rig
local pointToMove = character.Parent.Points["End Part 2"].Position
Torso.Position = Vector3.new(pointToMove)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文