#NPC AI issue related to MoveToFinished

1 messages · Page 1 of 1 (latest)

void pasture
#

So basically the ai works fine for a bit however, after a while it breaks for some reason I don't know why, Like it'll move to a few waypoints then stop for no apparent reason, the state changes work fine and there is no random state change between walk cycles

#

Thank you for your help

silent folio
#
    self.MoveToConnection = Humanoid.MoveToFinished:Connect(function(reached)
        if not reached then self.WalkFinished:Fire(); return end

        index += 1

        if index <= #Waypoints then
            Humanoid:MoveTo(Waypoints[index].Position)
        else
            self.WalkFinished:Fire()
        end
    end)``` pathfinding cancels part way through if the waypoint is not reached, and you are making duplicate connections to MoveToFinished event.
#

those duplicate connections are going to cause a lot of problems for any future pathfinding, they not able to get past the first waypoint

void pasture
#

I'm pretty sure the issue of duplicate connections I already solved by disconnecting the events

#

though I'll look into the cancelling part way through due to reached

#

but like the thing is

#

when if Walkfinished fires, I recompute a new path

silent folio
#

just because you put it in a variable doesnt mean the old one gets disconnected when you overwrite it hehe

void pasture
#

I do though self:CancelWalk

#

am I trippin or something

silent folio
void pasture
#

Walkfinished just call walk path, and inside walk path I cancel the walk

#

if a connection exist

#

like disconnect

silent folio
#
function GrandmaObject.WalkPath(self:Grandma, Destination:Vector3)
    if not Destination then return end

    self:CancelWalk()``` there it is
#

missed that

void pasture
#

yup

#

np

#

its the fact that it likes move to the second waypoint, then just stops that confuses me

#

and before hand it works fine

#

its just after like 4-5 cycles

#

its stops working

silent folio
#

increase the agent radius

void pasture
#

ok I will try, but how would that help?

silent folio
#

likely getting jammed on a wall or something

void pasture
#

its not that, like its basically just constantly traversing a house and what not, and even if it gets blocked it should recompute a path, and besides after the 4-5 cycles the problems keeps on repeating itself

#

but anyways trying right now

#

I'll tell you if it works

#

the ai works similar to granny

silent folio
#

i remember having a similar issue with my npc

#

cant remember what i did to fix it, but one of the symptoms was the waypoint visualizer kept rising up out of the ground and into the air, eventually becoming unreachable

void pasture
#

oh ye wait let me visualize this

#

I didn't try that

#

let me see

silent folio
#

i also think you may need more handling around lua if Path.Status ~= Enum.PathStatus.Success then return end here add a warn

#

particularly while devving

void pasture
#

Nope it creates the waypoints and they are all on the ground however it walks for a few seconds then just stops for some reason

void pasture
#

the script is still a work in progress, there still some stuff I want to refine but for now I just want to get this issue over with

#

ok so I think I noticed something

#

The path computes and what not

#

and the npc will continue walking that path

#

however will stop near an object whether its a wall or what not

#

I still don't get why it works before though

#

then stops randomly

silent folio
#

ya increase agent radius

#

so it doesnt get too close to wall

#

also review navmesh

#

use the roblox navmesh visualizer thingy, google the setting name

#

i suspect it may be trying to pathfind through a wall

#

or over it, rather

#

pathfinder tricky thing, lots of possible issues

void pasture
#

I use the navmesh visualiser, the path is computed and looks completely fine

silent folio
#

it could still be your state machine

void pasture
#

not over anything

#

I don't think I print whenever there is a state change

silent folio
#

could try moving the npc while the game is running to see what happens, on the server ofc

void pasture
#

Oh ye sure imma try that

silent folio
void pasture
#

ikr, its so annoying

#

like i've been on this for like 3 days

silent folio
#

and you didn't try that already?

void pasture
#

OH

#

moving it

#

will

#

make it work again

void pasture
silent folio
#

keep trialing stuff

#

specially now you have clear, easily reproducible symptom

#

actually thinking about it, it could also be network ownership

#
    for i,v:BasePart in self.Character:GetDescendants() do
        if v:IsA("BasePart") then v:SetNetworkOwner(nil) end
    end``` looks fine
void pasture
#

ok now sometimes it walks to third and 4th waypoint, however it like stutters for some reason

#

Oh one more thing @silent folio , you think this is S2 or nah?

silent folio
void pasture
silent folio
void pasture
#

thanks for your help, if you have any more ideas please be sure to share them

#

nah I lied

#

ye I think its a network owner ship issue

#

I used the Network Owner thing in the settings

#

and for some reason the character parts become are green

#

which in the docs means that they are owned by my character