简体   繁体   中英

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:

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.

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 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. 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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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