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

How would I turn this script into a path with multiple waypoints?

Asked by 1 year ago

script.Parent.Humanoid.WalkToPoint = Vector3.new(-2238.753, 956.457, -1050.838)

That is the script I have been using. I'm very new to using scripts with NPCs, and just barely managed to make that script. How would I make it into a path with multiple destinations? If I can't, what should I use to make a multi-destination pathfinding script?

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago
local function makeWaypoints(pos1, pos2, amount)
    if typeof(pos1) == "Vector3" and typeof(pos2) == "Vector3" then
        local waypoints = {}
        local pos1 = pos1
        local pos2 = pos2
        local amount = amount or 4
        local magnitude = -((pos1 - pos2).Magnitude) / amount
        local lastCF = CFrame.new(pos1, pos2) * CFrame.new(0, 0, -magnitude)
        for i = 1, amount + 1, 1 do 
            lastCF = CFrame.new(lastCF.Position, pos2) * CFrame.new(0, 0, magnitude)
            table.insert(waypoints, lastCF.Position)
        end
        return waypoints
    end
end

pos1 should be set to the position you want to start from,
pos2 should be set to the end position,
amount should be set to the amount of waypoints you want.

To get the waypoints loop through the table that makeWaypoints returns.

0
Thank you so much! LowlyKenna 2 — 1y
0
Does it work properly? ROMAHKAO 35 — 1y
Ad

Answer this question