Pathfinding within Specific area and randomized

Hello,

I am trying to find a method of being able to have a NPC randomly walk within a specific area, I have seen this done within a square as I can just restrict the position generated. However on this occasion I require the NPC to stay on a path which has curves and opens out onto a plaza so is not uniform in shape. I also need the NPC to randomly pick a spot to walk to within this specific area. I have tried using PathfindingModifier, however this just ensures the NPC avoids these blocks doesn’t restrict them to staying on it. Also how can it randomly pick a spot on top of this path as this is a large space I don’t want to have 100s of nodes for it to randomly pick from a table

Kind Regards
Tom

You might be able to generate a random list of nodes by picking a random position and checking if it can be reached via pathfinding. You could do this once and store it somewhere, instead of checking a new random position each time the NPC moves.

How would I do such a thing? sorry to be a pain

I don’t know that much about the builtin pathfinding but you could do raycast “raindrops” over an area and check each one for a valid path. You could use a part to define the area to check. I’m not sure this is preferable to just manually placing a few nodes, which might be better as the player will gradually learn the small list of places an NPC can be in an area.

1 Like

Do you think it would work if I reversed the pathfindingmodifer. So I insert it into parts I want it to walk on and that way when it generates a spot if it finds a spot that collides/touches the part with a PFM its set to true and uses this to walk towards? :s

1 Like

Is it possible for a position to be picked which is ontop/incontact with a certain part? This part is a union so does not form a typical square shape

Yes but again automatically generating this point would be a lot of work (you could still use whitelist raycasts to “drop” random points on an object), compared to manually placing a smaller number of points.