How can I make a pathfinding beam?

So I have made a little arrow thing that points you to the place you’re supposed to go in the game, shown in the screenshot.

I want to make this beam curve around terrain and parts using PathfindingService or something similar, to make the beam follow a spline-path to the location. Anyone know how I can put multiple points on a beam?

(I’ve looked on the forum, and all I can find about pathfinding is for NPCs, and all I can find about beams is straight lines or single/double curves, so I don’t know where to look)

That’d be really neat, but unfortunately as far as I’m aware that isn’t possible using the Roblox beam object. Probably would require a bit of math to do it otherwise, definitely not the guy to tell you how unfortunately :joy:

1 Like

Use PathfindingService to create a path. This will give you a table of waypoints. You could attach beams in between the waypoints.

4 Likes

So use multiple beam clones in between each point?

2 Likes

Yes probably. Thats the only way I can think of. :thinking:

3 Likes
local PathfindingService = game:GetService("PathfindingService")

local endpoint = workspace.endpoint
local startpoint = workspace.startpoint

local path = PathfindingService:CreatePath()

path:ComputeAsync(startpoint.Position, endpoint.Position)

local waypoints = path:GetWaypoints()

local Folder = Instance.new("Folder")
Folder.Name = "Waypoints"
Folder.Parent = workspace

for i, v in ipairs(waypoints) do
	local Part = Instance.new("Part")
	Part.Position = v.Position
	Part.Anchored = true
	Part.Size = Vector3.new(1, 1, 1)
	Part.Parent = Folder
	if (i > 1) then
		local lastWaypoint = waypoints[i - 1]
		local dist = (v.Position - lastWaypoint.Position).Magnitude
		local Part2 = Instance.new("Part")
		Part2.Anchored = true
		Part2.BrickColor = BrickColor.Black()
		Part2.Size = Vector3.new(.5, .5, dist)
		Part2.CFrame = CFrame.new(lastWaypoint.Position, v.Position) * CFrame.new(0, 0, dist / -2)
		Part2.Parent = Folder
	end
end
2 Likes

Thanks for the code, I was looking for beams and not parts, but the pathfinding loop was exactly what I was looking for.