简体   繁体   English

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

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

So i'm trying to make a little bot that moves to a point in the map Here is my code:所以我正在尝试制作一个移动到 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)

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.当我启动游戏时,虚拟人 model 根本不动(即使 WalkToPoint 已正确设置),然后几秒钟后控制台打印消息Reached Dest但人形机器人没有移动。 I have no idea why this happend, could you please help me.我不知道为什么会这样,你能帮帮我吗? Thank you so much.太感谢了。

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

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.第二个是目前 Roblox 似乎存在问题,因为在这种情况下使用您自己定义的 Vector3s 几乎是不可能的,因为人形机器人不会移动到 position,而是大约 5-10 个螺柱。 I had this problem and this is how I fixed it.我遇到了这个问题,就是我解决它的方法。 I hope this helps!我希望这有帮助!

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

Aside from what I said below, testpoint is not set as a Vector, which ends up messing stuff up.除了我在下面所说的之外,testpoint 没有设置为 Vector,这最终会把事情搞砸。 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:但是,您不需要使用 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)

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另外请确保您正确获取先前的变量,如characterhumanoid

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

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