Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do you use moveto but only allow the character to move along a certain path?

Asked by 8 years ago

When you use moveto, the character in a straight line to the location you want it to go to. What if I want it to, for example, go around a rock that is in it's path during the process?

Also is there a way to change the rock's position according to an int value (1= 1 stud away from spawn) and change the character's path with it?

0
how is moveto being called is it from the player clicking on the game world? or is the player being moved after an event what? ProfessorSev 220 — 8y
0
I want to call it when the intvalue of the rock's position changes Volodymyr2004 293 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Use Pathfinding,

local TheFirst = script.Parent.TheNpc.Humanoid -- Change TheNpc to your npc's name

local In = game.Workspace.FirstBrick  -- Start Point
local Out = game.Workspace.SecondBrick -- Finish Point

local Click = game.Workspace.Click -- I clickable part to make him move

local path = game:GetService("PathfindingService"):ComputeRawPathAsync(In.Position, Out.Position, 500) -- Don't ask me "Why 500?" I don't know.
local points = path:GetPointCoordinates()


Click.ClickDetector.MouseClick:connect(function()
    for _, point in pairs(points) do
        print("moving to: ", point)
        TheFirst:MoveTo(point)
        -- Don't try moving to the next point until we are close enough to the current point in the path
        repeat
            local distance = (point - TheFirst.Parent.Torso.Position).magnitude
            wait()
        until distance < 3
    end
end)

1) Change TheNpc to your npc's name 2) Make two bricks in the workspace , one called FirstBrick (Start point) and another one called SecondBrick (FinishPoint) 3)Make a brick in the workspace called Click, with a click detector inside. 4) Place the script in the workspace.

TIP: The npc will take the fastest way to the finish point.

If that doesn't work check: http://wiki.roblox.com/index.php?title=Pathfinding

Ad

Answer this question