Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

2 comments

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?

0

I want to call it when the intvalue of the rock's position changes

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.