#path finding failed attempt

1 messages · Page 1 of 1 (latest)

austere shadow
#
local pathfinding = game:GetService("PathfindingService")
local engine = script.Parent
local ikarus = engine.Parent.Parent
local velo = engine:WaitForChild("BodyVelocity")

local accel = 10
local brake = 25
local maxSpeed = 35
local speed = 0

local function getClosestStop()
    local pos = ikarus:GetPivot().Position
    local nearest
    local dist = math.huge
    for _, v in workspace:GetChildren() do
        if v:IsA("BasePart") and v.Name:lower():find("stop") then
            local d = (v.Position - pos).Magnitude
            if d < dist then
                nearest = v
                dist = d
            end
        end
    end
    return nearest
end

local function driveTo(destination, rerouteCount)
    rerouteCount = rerouteCount or 0
    if rerouteCount > 5 then
        warn("🛑 bus lost after too many reroutes")
        speed = 0
        velo.Velocity = Vector3.zero
        return false
    end

    local start = ikarus:GetPivot().Position
    local path = pathfinding:CreatePath({
        AgentRadius = 4,
        AgentHeight = 6,
        AgentCanJump = false, -- common sense
        AgentCanClimb = false -- here too
    })
    path:ComputeAsync(start, destination.Position)

    if path.Status ~= Enum.PathStatus.Success then
        warn(" bus lost, path failed")
        speed = 0
        velo.Velocity = Vector3.zero
        return false
    end
```lua
tame magnet
tame magnet
#

youve defined them

#

but you havent used them

austere shadow
#

ye

#

give me a sec

#

thats only the part of the script

#

not the whole script

tame magnet
#

use pastebin

austere shadow
#

yeah i think i used them

tame magnet
#

bro show the code

#

💀

austere shadow
#

i was on another project

#

like have some damn patience

tame magnet
#

if ur gonna be rude get ur own help

austere shadow
#

i am not

tame magnet
#

bc you cant js

austere shadow
#

okay here it is

tame magnet
#

give half the code

#

and say fix it

austere shadow
#

local waypoints = path:GetWaypoints()
print("🛣️ found path with", #waypoints)
if DEBUG_PATH then
drawDebugPath(waypoints)
end

for i = 1, #waypoints do
    local wp = waypoints[i]
    local reached = false
    while not reached do
        if isBlocked(destination) then
            print(" lock on road, time for shortcut (reroute attempt " .. (rerouteCount+1) .. ")")
            speed = 0
            velo.Velocity = Vector3.zero
            task.wait(0.5)
            return driveTo(destination, rerouteCount + 1)
        end

        local pos = ikarus:GetPivot().Position
        local dir = (wp.Position - pos)
        local dist = dir.Magnitude

        if dist < 2 then
            reached = true
        else
            local diff = maxSpeed - speed
            if math.abs(diff) > 0.1 then
                speed += math.sign(diff) * ((diff > 0) and accel or brake) * 0.1
            end
            velo.Velocity = dir.Unit * speed
        end

        task.wait(0.05)
    end
end

speed = 0
velo.Velocity = Vector3.zero
print(" arrived. brakes working. nobody dead.")
return true

end

local function startBus()
while true do
local stop = getClosestStop()
if stop then
local success = driveTo(stop)
if success then
break
else
warn("❌ bus failed to reach stop, retrying in 2 seconds")
task.wait(2)
end
else
warn("❌ no stops found. bus is confused.")
break
end
end
clearDebug()
end

startBus()

#

i even tried asked chatgbt but even it crashed

#

got this from a path finding template, and tweaked it

austere shadow
azure nicheBOT
#

studio** You are now Level 2! **studio

tame magnet
#

can you give more info

austere shadow
#

what info

#

thats the full script

tame magnet
#

like is the whole pathfinding not running

#

is it going halfway

#

etc

austere shadow
#

its not even moving

#

it just said

#

"lost"

#

body velocity at 0

tame magnet
#

isnt speed always at 0

#

it never changes if im not mistaken

austere shadow
#

well

tame magnet
#

acc wait

#

im bugging

austere shadow
#

copy paste it into a part, with a body velocity

#

like trying to caculate how the bus gonna get to the first way point is complex

#

with body velocity and angular velocity, too complex

tame magnet
#

wait what line does it say lost

austere shadow
#

old verison, or this

tame magnet
#

this

austere shadow
#

but new version

#

it does nothing

tame magnet
#

wdym old and new

austere shadow
#

nvm

tame magnet
#

is the script you sent the new version

austere shadow
#

ye

#

not new version, half of the script, but either way, new version it dosent say lost

#

it just does nothing

#

the lost log is no stops found

tame magnet
#

add a wait

austere shadow
#

where

tame magnet
#

before startBus()

austere shadow
#

same result

tame magnet
#

whats DEBUG_PATH and drawDebugPaths()

#

its not defined

austere shadow
#

it just draws debug path, rn its not needed

tame magnet
#

yh but its not defined

austere shadow
#

local function drawDebugPath(waypoints) clearDebug() local folder = Instance.new("Folder") folder.Name = "BusPathDebug" folder.Parent = workspace for i = 1, #waypoints do local wp = waypoints[i] local part = Instance.new("Part") part.Anchored = true part.CanCollide = false part.Shape = Enum.PartType.Ball part.Size = Vector3.new(1,1,1) part.Position = wp.Position part.Color = Color3.fromRGB(255, 200, 0) part.Transparency = 0.3 part.Name = "WP_"..i part.Parent = folder if i > 1 then local prev = waypoints[i-1] local beam = Instance.new("Part") beam.Anchored = true beam.CanCollide = false beam.Size = Vector3.new(0.3,0.3,(wp.Position-prev.Position).Magnitude) beam.CFrame = CFrame.new(prev.Position, wp.Position) * CFrame.new(0,0,-beam.Size.Z/2) beam.Color = Color3.fromRGB(255, 100, 0) beam.Transparency = 0.5 beam.Name = "Line_"..(i-1) beam.Parent = folder end end end

#

DEBUG_PATH is true

tame magnet
#

yh idk srry but js check if each function is running

austere shadow
#

if everything aint working correctly, it would throw an error anyways

#

wait a second, im going to make a test part...

austere shadow
#

this test run works

#

@tame magnet the test run works, then why does this not work?