繁体   English   中英

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

[英]Humanoid:MoveTo() doesn't work | Roblox LUA

所以我正在尝试制作一个移动到 map 中某个点的小机器人 这是我的代码:

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)

当我启动游戏时,虚拟人 model 根本不动(即使 WalkToPoint 已正确设置),然后几秒钟后控制台打印消息Reached Dest但人形机器人没有移动。 我不知道为什么会这样,你能帮帮我吗? 太感谢了。

您可能需要考虑几件事:首先,您需要确保人形生物所在的 model 中的所有部分都未锚定,否则它不会移动,即使它会触发“MoveToFinished” “就像它为你所做的那样。

第二个是目前 Roblox 似乎存在问题,因为在这种情况下使用您自己定义的 Vector3s 几乎是不可能的,因为人形机器人不会移动到 position,而是大约 5-10 个螺柱。 我遇到了这个问题,就是我解决它的方法。 我希望这有帮助!

类人动物:移动到(测试点)

除了我在下面所说的之外,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)

在尝试将实例属性存储在变量中之前,我遇到过问题。 你应该试试:

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)

另外请确保您正确获取先前的变量,如characterhumanoid

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM