Pathfinding For a Part?

Is there such a thing to make a pathfinding script, (or something like that) just using 1 part?

For example, instead of having a whole rig and needing to pathfind that, can you just move a part from one place to another using pathfinding?

The reason I want pathfinding, is because there are corners, and I don’t want my part to go through wall.

(i also don’t want other parts to act like “waypoints” for the main part)

Any help is appreciated!

1 Like

Here’s a sample code that you can use to create a pathfinding script for a part in Roblox:

local part = game.Workspace.Part -- Replace "Part" with the name of your desired part

local pathfindingService = game:GetService("PathfindingService")
local path = pathfindingService:CreatePath()

local destination = Vector3.new(0, 5, 0) -- Replace these coordinates with the destination coordinates
path:ComputeAsync(part.Position, destination)

local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
    local move = Instance.new("MoveTo")
    move.Target = waypoint.Position
    move.Parent = part
    move:Play()
    move.Completed:Wait()
end

Simply replace the name of the part you want to create a pathfinding script for, as well as the destination coordinates, and this code should work for you. Have fun!

2 Likes

I can’t stop laughing. It’s obvious this was written using ChatGPT.

Anyways, the code above will mostly work, but you need to replace these lines:

With this:

local speed = 5 --replace with speed you want the part to go at.
local t = 0
local max = (part.Position-waypoint.Position).Magnitude/speed
local waitTime = 0 --increase if laggy

while t < max do
part.CFrame = part.CFrame:Lerp(CFrame.lookAt(part.CFrame.Position, waypoint.Position), t/max)
t += task.wait(waitTime)
end

Code Written on DevForum. It might not work and have formatting errors.

7 Likes

I’am just a newbies, pls stop the bully on me goddawmn

2 Likes

It’s okay. It’ll mostly work from here on.

3 Likes

Sorry for the late response, but I think it’s working, but what are the conditions do the part need to be in? Achored? Cancollide? etc?

This is good, but like @SubtotalAnt8185 said, the code inside the for loop doesn’t work.

I wouldn’t post AI responses then, learn and then start posting

2 Likes

I’m deadddd 10/10 response lol

3 Likes