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

Magnitude not working as expected?

I am trying to make an NPC stop moving once it gets near the point it is moving to. According to the print, the magnitude is big enough to allow it to move. Why wouldn't it be working? It is just pathfinding to a random node. Should I make it move to the nearest node instead? I would use moveToFinished but that is slower.

Here is my code:

--wait(30)

local nodes = game.Workspace.Nodes:GetChildren()
local pathService = game:GetService("PathfindingService")

while true do
	math.randomseed(tick())
	wait()
	randomNode = math.random(1, #nodes)
	path = pathService:ComputeRawPathAsync(script.Parent.DecalPart.Position, nodes[randomNode].Position, 10000)
	points = path:GetPointCoordinates()
	script.Parent.DecalPart.SweepSound:Play()
	for _, point in pairs(points) do
		script.Parent.SweepHumanoid:MoveTo(point)
		repeat wait() print((script.Parent.Head.Position - point).magnitude) until (script.Parent.Head.Position - point).Magnitude < 1
	end
end

1 answer

Actually, I just messed up. Magnitude < 1 IS too small

1 comment

0

Can you awnser my question?

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