Hello.
I was scripting a npc that can pathfind efficently and use the minimun amount of server resources. While testing the npc I came into a little problem. The npc kept on pausing between waypoints so I wanted to reduce those waypoints and here i coded a function that does so.
It finds the difference between waypoints directions and deletes the ones that go in a strait line or is not a jumping waypoint. Heres the code
local function FindImportantWaypoints(Path)
local waypointss=Path:GetWaypoints()
local CurrentDiff=Vector2.new(0,0)
local Important={}
for i, waypoint in ipairs(waypointss) do
if i~=#waypointss then
local RnPos=waypoint.Position
local NextWaypointPos=waypointss[i+1].Position
local Diff=(Vector2.new(RnPos.X,RnPos.Z)-Vector2.new(NextWaypointPos.X,NextWaypointPos.Z))
if (CurrentDiff-Diff).Magnitude>.072 or waypoint.Action == Enum.PathWaypointAction.Jump or waypoint.Label=="Climb" then
table.insert(Important,waypoint)
if waypoint.Action == Enum.PathWaypointAction.Jump or waypoint.Label=="Climb" then
if waypointss[i+1] then
table.insert(Important,waypointss[i+1])
end
end
if waypoint.Label=="Swim" then
table.insert(Important,waypoint)
end
end
CurrentDiff=Diff
end
end
table.remove(Important,1)--First waypoint is %99.0 useless
return Important
end
--strategic_oof
This function finds a important role in my npc’s pathfinding and reduces the amount of pausing and studdering significantly.
Your free to use it!!
My goal is to clean up this function and make it as simple as possible.