Roblox Studio Tutorial: Pathfinding (Creating a Path)
Roblox Studio Tutorial: Pathfinding (Moving Objects on Path)
Roblox Studio Tutorial: Pathfinding (Moving NPC Humanoids)
Roblox Studio Tutorial: Pathfinding (Jump Over Obstacles)
-- Illustrate Path
```
local pathParts = game.Workspace.Path
local start = game.Workspace.Start
local finish = game.Workspace.Finish
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
path:ComputeAsync(start.Position, finish.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
pathParts:ClearAllChildren()
-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = pathParts
end
```
- Move Part on Path
```
local pathParts = game.Workspace.Path
local start = game.Workspace.Start
local finish = game.Workspace.Finish
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
path:ComputeAsync(start.Position, finish.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
pathParts:ClearAllChildren()
-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = pathParts
start.Position = waypoint.Position
wait(0.1)
end
```
-- Redraw Path
```
local pathParts = game.Workspace.Path
local start = game.Workspace.Start
local finish = game.Workspace.Finish
local PathfindingService = game:GetService("PathfindingService")
while true do
local path = PathfindingService:CreatePath()
path:ComputeAsync(start.Position, finish.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
pathParts:ClearAllChildren()
-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = pathParts
end
wait(0.1)
end
```
-- Object Tracking
```
local start = game.Workspace.Start
local finish = game.Workspace.Finish
local PathfindingService = game:GetService("PathfindingService")
while true do
local path = PathfindingService:CreatePath()
path:ComputeAsync(start.Position, finish.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
-- Loop through waypoints
for i = 1, 5 do
if i <= #waypoints then
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoints[i].Position
part.Anchored = true
part.CanCollide = false
part.Parent = pathParts
start.Position = waypoints[i].Position
wait(.1)
end
end
end
```
-- Moving Humanoid Models
```
local pathParts = game.Workspace.Path
local start = game.Workspace.Start
local finish = game.Workspace.Finish
local dummy = game.Workspace.Dummy
local humanoid = dummy.Humanoid
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
path:ComputeAsync(dummy.Torso.Position, finish.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
pathParts:ClearAllChildren()
-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = pathParts
end
for _, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
```
-- Humanoid Model Object Tracking
```
local pathParts = game.Workspace.Path
local finish = game.Workspace.Finish
local dummy = game.Workspace.Dummy
local humaoid = dummy.Humanoid
local PathfindingService = game:GetService("PathfindingService")
while true do
local path = PathfindingService:CreatePath()
path:ComputeAsync(dummy.Torso.Position, finish.Position)
local waypoints = path:GetWaypoints()
for i = 1, 5 do
if i <= #waypoints then
if waypoints[i].Action == Enum.PathWaypointAction.Jump then
humaoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humaoid:MoveTo(waypoints[i].Position)
humaoid.MoveToFinished:Wait()
end
end
end
```
'tech > game' 카테고리의 다른 글
21/08/02 How to build a water slide in ROBLOX 2020 Easy! (0) | 2021.08.02 |
---|---|
21/08/01 HOW TO MAKE YOUR OWN SKYBOX (CUBEMAP) IN ROBLOX STUDIO (0) | 2021.08.01 |
21/08/01 Roblox Studio Tutorial: How to Move a Part With a Button (0) | 2021.08.01 |
21/07/31 Roblox Studio Tutorial: Starting Menu (0) | 2021.07.31 |
21/07/31 Roblox Studio Tutorial: How to Make a Pop-up Menu (0) | 2021.07.31 |