Skip to content

Non-Humanoid Examples

Pathfinding for non-humanoid models can get a little complicated. Consider converting your non-humanoid model to a humanoid if possible.


Example 1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local SimplePath = require(ServerStorage.SimplePath)

local Model = workspace.Model
local Goal = workspace.Goal
local Path = SimplePath.new(Model)

local function tween(part, destination)
    local tweenBase = TweenService:Create(part, TweenInfo.new(0.07), {Position = destination + Vector3.new(0, 0.5, 0)})
    tweenBase:Play()
    tweenBase.Completed:Wait()
end

Path.Visualize = true

--Tween model to final waypoint when reached
Path.Reached:Connect(function(model, finalWaypoint)
    tween(model.PrimaryPart, finalWaypoint.Position)
end)

--Call Path:Run() at the end of the event to indicate the end of movement for the current waypoint
Path.WaypointReached:Connect(function(model, lastWaypoint, nextWaypoint)
    tween(model.PrimaryPart, nextWaypoint.Position)
    Path:Run()
end)

Path:Run(Goal)

Example 2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local SimplePath = require(ServerStorage.SimplePath)

local Model = workspace.Model
local Goal = workspace.Goal
local Path = SimplePath.new(Model)

local function tween(part, destination)
    local tweenBase = TweenService:Create(part, TweenInfo.new(0.07), {Position = destination + Vector3.new(0, 0.5, 0)})
    tweenBase:Play()
    tweenBase.Completed:Wait()
end

Path.Visualize = true

--If the path is blocked
Path.Blocked:Connect(function()
    Path:Run(Goal)
end)

--In case of an error
Path.Error:Connect(function()
    Path:Run(Goal)
end)

Path.Reached:Connect(function(model, finalWaypoint)
    tween(model.PrimaryPart, finalWaypoint.Position)
    Path:Run(Goal)
end)

Path.WaypointReached:Connect(function(model, lastWaypoint, nextWaypoint)
    tween(model.PrimaryPart, nextWaypoint.Position)
    Path:Run(Goal)
end)

Path:Run(Goal)

Example 3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local SimplePath = require(ServerStorage.SimplePath)

local Model = workspace.Model
local Goal = workspace.Goal
local Path = SimplePath.new(Model)

Path.Visualize = true

Path.Reached:Connect(function(model, finalWaypoint)
    model.PrimaryPart.Position = finalWaypoint.Position + Vector3.new(0, 0.5, 1)
end)

Path.WaypointReached:Connect(function(model, lastWaypoint, nextWaypoint)
    model.PrimaryPart.Position = nextWaypoint.Position + Vector3.new(0, 0.5, 1)
end)

while true do
    Path:Run(Goal)
    task.wait()
end