I am excited to release EZ Pathfinding V3 today!! After a month or so of programming V2, I decided to start on a brand new version with better features and better compatibility. There are added features such as making a part jump which is still being modified. If you are having trouble using it, read the instructions below. V2 is no longer being modified or updated, but V3 will. V3 will probably be the last version, but will be constantly updated.
About this Module:
The EZ Pathfinding modules are designed to make using pathfinding a whole lot easier. These modules also include special functions that make controlling parts and NPCs a whole lot easier. V3 has more functions and is more compatible and easier to modify than V2. V2 will still be open to the public, but I strongly suggest if you want one of these modules, that you get V3.
Instructions
- To create the path that your part or npc is going to use, you will have to use the module.new(params) function : Example :
local module = require(5697665462) -- or require(game:GetService("ReplicatedStorage"):FindFirstChild("MainModule"))
local path = module.new(NPC, endPart) -- replace startPart and endPart with Instances
- To get your part or npc to move, you will need to use the module:Move(params) function : Example :
module:Move(path, NPC)
- If you want to change the settings for the pathfinding, you can do so using the module.SetSettings(params) function : Example :
module.SetSettings("Tween_Info", TweenInfo.new(tweenParams))
List of Setting Types
"Tween_Info",
"Walk_Speed",
"Jump_Power",
"PFparams"
- After using these instructions your code look something like this:
local module = require(5697665462) -- or require(game:WaitForChild("ReplicatedStorage"):WaitForChild("MainModule"))
module.SetSettings("Tween_Info", TweenInfo.new(tweenParams))
local path = module.new(NPC, endPart) -- replace startPart and endPart with Instances
module:Move(path, NPC)
Extra Module Functions
-
module.Jump(NPC, power) -- makes a part or npc jump. Power only is for part jumping. JumpPower can be modified in the function, module.SetSettings()
-
module.PauseTweening(partName) -- pauses a tween for parts with the name of the partName param
-
module.ResumeTweening(partName) -- resumes a tween for parts with the name of the partName param
-
module.StopNPC(npc) -- stops that npc's current path completely
-
module.PauseNPC(npc) -- pauses that npc's current path. Can be resumed.
-
module.ResumeNPC(npc) -- resumes that npc's current path. Works only if it is paused.
-
module.GetNearestPlayer(npc, maxDistance) -- fetches the nearest player and returns the player object.
-
module.ChaseNearestPlayer(path, npc) -- Chases the player computed in the path. Same as doing module:Move(path, npc)
-
module.ClearPartWaypoints() -- clears every parts waypoints and sends them to the debris where they will have a lifetime of three seconds to be tweened too if not already.
-
module.ArrayMovement(npc, {[1] = part1, [2] = part2, [3] = part3} -- Moves an npc to the first part then the next and next with ease. No part count limit but distance between parts cannot be too far.
Script Functions
-
module.RigWaypointReached = function() end -- triggers every time a
npcreaches a new waypoint
-
module.PartWaypointReached = function() end -- triggers every time a
partreaches a new waypoint
Link to the V3 and V2:
EZ Pathfinding V3:
EZ Pathfinding V2 (older version):
- Module: EZ Pathfinding V2 (OUTDATED) - Roblox
- Thread: EZ Pathfinding V2 [OUTDATED]
EZ Pathfinding V3 Test Place (Uncopylocked):
Source Code
local module = {}
local meta = {}
module.__index = module
local self = setmetatable(meta, module)
local AR, AH, ACJ = 5, 10, true
--// Services
local Pathfinding = game:GetService("PathfindingService")
local tservice = game:GetService("TweenService")
local debris = game:GetService("Debris")
--// Variables
local currentWaypointIndex = 2
local currentTweenPart
local ptpause = false
local StoppedPath = false
--//Tables
local paused = {[1] = {Number = 1, Name = ""}}
local waypoints = nil
--local stopped = {[1] = {Number = 1, Name = ""}}
module.PartWaypointReached = {}
module.RigWaypointReached = {}
--//Tweening
local tweeninfo = TweenInfo.new(
3,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
--// Functions
local function onWaypointReached(reached, npc)
local humanoid = npc:FindFirstChildOfClass("Humanoid")
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
if typeof(module.RigWaypointReached) == "function" then
module.RigWaypointReached()
end
end
end
local function onPathBlocked(blockedWaypointIndex, npc, endpart, vector)
if blockedWaypointIndex > currentWaypointIndex then
if vector == true then
local path = module.new(npc, vector)
module:Move(path, npc)
else
local path = module.new(npc, endpart)
module:Move(path, npc)
end
end
end
function module.new(npc, endpart, vector)
local params = {AgentRadius = AR, AgentHeight = AH, AgentCanJump = ACJ}
local path = Pathfinding:CreatePath(params)
if npc:FindFirstChildOfClass("Humanoid")then
if vector ~= nil then
path:ComputeAsync(npc:WaitForChild("HumanoidRootPart").Position, vector)
path.Blocked:Connect(onPathBlocked, npc, endpart, vector)
else
path:ComputeAsync(npc:WaitForChild("HumanoidRootPart").Position, endpart.Position)
path.Blocked:Connect(onPathBlocked, npc, endpart, vector)
npc.Humanoid.MoveToFinished:Connect(function(status)
onWaypointReached(status, npc)
end)
end
elseif npc:IsA("BasePart")then
if vector ~= nil then
path:ComputeAsync(npc.Position, vector)
else
path:ComputeAsync(npc.Position, endpart.Position)
end
end
return path
end
function module:Move(path, npc)
if path then
waypoints = path:GetWaypoints()
local hum
waypoints = path:GetWaypoints()
if npc:FindFirstChildOfClass("Humanoid")then
hum = npc:FindFirstChildOfClass("Humanoid")
end
if path.Status == Enum.PathStatus.Success then
if hum then
if waypoints[currentWaypointIndex] then
hum:MoveTo(waypoints[currentWaypointIndex].Position)
hum.MoveToFinished:Wait()
end
else
StoppedPath = false
ptpause = false
local currentpartt
currentTweenPart = npc
currentTweenPart.Anchored = true
for i, waypoint in pairs(waypoints) do
wait(1)
if ptpause == false then
local newpart = Instance.new("Part")
newpart.Position = waypoint.Position
newpart.Size = Vector3.new(0.6,0.6,0.6)
newpart.Shape = "Ball"
newpart.Anchored = true
newpart.CanCollide = false
newpart.Name = "Waypoint:EzPathfindingV3"
newpart.Parent = workspace
newpart.Transparency = 1
newpart.Touched:Connect(function()
if typeof(module.PartWaypointReached) == "function" then
module.PartWaypointReached()
end
end)
wait(0.1)
pcall(function()
local part = currentTweenPart
if newpart.Name == "Waypoint:EzPathfindingV3" then
local goal = {Position = newpart.Position}
local tween = tservice:Create(part, tweeninfo, goal)
local pause = false
local stopped2 = false
for _,v in pairs(paused)do
if v then
if v.Name then
if currentTweenPart.Name == v.Name then
--ptpause = true
tween:Pause()
pause = true
else
if pause == false then
if stopped2 == false then
--ptpause = false
tween:Play()
end
end
end
end
else
if pause == false then
if stopped2 == false then
tween:Play()
end
end
end
end
--[[for _, value in pairs(stopped)do
if value then
if value.Name then
if currentTweenPart.Name == value.Name then
tween:Cancel()
stopped2 = true
end
end
end
end--]]
end
end)
end
end
end
else
if hum then
hum:MoveTo(npc.HumanoidRootPart.Position)
end
end
end
end
function module.SetSettings(setType, info, char)
if setType == "Tween_Info" then
local Time = info.Time
local style = info.EasingStyle
local direction = info.EasingDirection
local rCount = info.RepeatCount
local reverses = info.Reverses
local delaytime = info.DelayTime
local info = TweenInfo.new(
Time,
style,
direction,
rCount,
reverses,
delaytime
)
tweeninfo = info
end
if setType == "Jump_Power" then
if char then
if char:FindFirstChildOfClass("Humanoid") then
local hum = char:FindFirstChildOfClass("Humanoid")
hum.JumpPower = info
self.JumpPower = info
end
end
end
if setType == "Walk_Speed" then
if char then
if char:FindFirstChildOfClass("Humanoid") then
local hum = char:FindFirstChildOfClass("Humanoid")
hum.WalkSpeed = info
self.WalkSpeed = info
end
end
end
if setType == "PF_Params" then
local agentHeight = info.AgentHeight
local agentRadius = info.AgentRadius
local agentCanJump = info.AgentCanJump
AR, ACJ, AH = agentRadius, agentCanJump, agentHeight
end
if setType == "All" then
if char then
if char:FindFirstChildOfClass("Humanoid") then
local hum = char:FindFirstChildOfClass("Humanoid")
hum.JumpPower = info.JumpPower or 50
self.JumpPower = info.JumpPower or 50
hum.WalkSpeed = info.WalkSpeed or 16
self.WalkSpeed = info.WalkSpeed or 16
end
end
local agentHeight = info.AgentHeight or 10
local agentRadius = info.AgentRadius or 5
local agentCanJump = info.AgentCanJump or true
AR, ACJ, AH = agentRadius, agentCanJump, agentHeight
end
end
function module.PauseTweening(partName)
local number = #paused +1
paused[number] = {Number = number, Name = partName}
end
--[[function module.StopTweening(partName)
local number = #stopped + 1
stopped[number] = {Number = number, Name = partName}
end--]]
function module.ResumeTweening(partName)
for _,v in pairs(paused)do
if v.Name == partName then
local num = v.Number
table.remove(paused, num)
end
end
end
function module.StopNPC(npc)
if npc:FindFirstChildOfClass("Humanoid")then
local hum = npc:FindFirstChildOfClass("Humanoid")
hum:MoveTo(npc.HumanoidRootPart.Position)
end
end
function module.PauseNPC(npc)
for _,v in pairs(npc:GetChildren())do
if v:IsA("BasePart")then
v.Anchored = true
end
end
end
function module.ResumeNPC(npc)
for _,v in pairs(npc:GetChildren())do
if v:IsA("BasePart")then
v.Anchored = false
end
end
end
function module.Jump(npc, power)
if npc then
if npc:FindFirstChildOfClass("Humanoid")then
local hum = npc:FindFirstChildOfClass("Humanoid")
if power ~= nil then
hum.JumpPower = power
end
hum:Jump()
else
npc.Velocity = Vector3.new(0, 0, 0) -- reset velocity
module.PauseTweening(npc.Name)
local touchingTable = {[1] = "true"}
local touching = npc:GetTouchingParts()
repeat
wait(0)
touchingTable = npc:GetTouchingParts()
npc.Position = npc.Position + Vector3.new(0, 5, 0)
until
touchingTable[1] == nil
local Storage = Instance.new("Folder", script)
for _, v in pairs(npc:GetChildren())do
if v:IsA("Weld") or v:IsA("WeldConstraint")then
v.Parent = Storage
end
end
wait(0.3)
npc.Velocity = Vector3.new(0, power, 0)
npc.Anchored = false
repeat
wait(0.1)
until
npc:GetTouchingParts()[1] ~= nil
npc.Anchored = true
module.ResumeTweening(npc.Name)
end
end
end
function findNearestTorso(pos, npc, dist)
local list = game.Workspace:GetChildren()
local torso = nil
local temp = nil
local human = nil
local temp2 = nil
for i = 1, #list do
temp2 = list[i]
if temp2.ClassName == "Model" then
if temp2 ~= npc then
temp = temp2:FindFirstChild("HumanoidRootPart")
human = temp2:FindFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
end
return torso
end
function module.GetNearestPlayer(npc, maxDis)
if npc then
if npc:FindFirstChild("HumanoidRootPart") then
local humRoot = npc:FindFirstChild("HumanoidRootPart")
local target = findNearestTorso(humRoot.Position, npc, maxDis)
local path = module.new(npc, target)
self.CurrentPlrPath = path
self.CurrentTarget = target
return path
end
end
end
function module.ChaseNearestPlayer(path, npc)
module:Move(path, npc)
end
function module.ClearPartWaypoints()
for _, v in pairs(game.Workspace:GetChildren())do
if v then
if v.Name == "Waypoint:EzPathfindingV3" then
debris:AddItem(v, 3)
end
end
end
end
return module
If you have any suggestions or questions, please reply to this thread and I’ll reply back as quickly as possible. If you have any concerns, message me so we can privately bug fix or solve your issue.
Poll (please only vote if you have tried out this module):
- I love this module, no feedback.
- I have some feedback (Reply)
- I have a lot of feedback (Reply)
0 voters
An update log will be kept here for updates:
Update Log
10/11/20 - Smooth tween to jump transitions / Tweening doesn't overide jumping.
10/12/20 - Added new functions. (GetNearestPlayer, ChaseNearestPlayer, ClearPartWaypoints). Documentation on them located on the Extra Module Functions tab.
10/17/20 - ArrayMovement Function. Allows movement from part to part in one function. Requires an array of parts with indexes counting up (e.g. 1, 2, 3). Documentation located in the Extra Module Functions tab.
Thank you for reading this and I hope you have a fabulous day!