Hey, I’m currently working on a simulator game, and I currently have breakables which are noobs, how would i go about making them walk around randomly? Currently, the noobs doesnt do anything which is weird, so thats why i want to make that
I suggest that you place many invisible parts on your map. Those will be the places where the noobs will go. The more of these parts you’ll have, the more different the places they can go to.
Then, you can store all these parts in a table numbered from 1,2,3, etc until your last part.
You can then generate a random number between 1 and the number of parts you have. You can then pathfind the noob’s way to the part associated with the number generated in the table at its index.
Quick code example :
parts = map.StandPoint:GetChildren() -- The studio's explorer path to all the parts on the map
-- Here, :GetChildren() will automatically put all your parts in an ordered table
gotoNumber = math.random(1, #parts) -- One random index from the table
PathFind(npc, parts[gotoNumber]) -- You have to make the PathFind function
You can search how to pathfind a way here
This is a reasonable approach. By defining points where the NPCs can go to, it reduces the need for recalculation if random points around the NPC were being picked but are inaccessible (i.e., the destination is in a wall or impossible to get to).
Nonetheless, the approach of picking a random point in the NPC’s radius is still a viable solution I use with my zombie NPCs. But depending on the author’s goal, they may not want the NPC to go all the way across the map.
Yes of course, you can exclude elements from the table depending on the distance the part is to the npc. You might also want to add a minimal distance of travel to a different part, or a part where no other npc is going, etc…
hey, I have found a game with basically the thing I need, do you think this is the way that they used?
From what I can tell, it seems to be what I said. I think they go between 12 invisible parts (4 on the left vertically, 4 on the middle lane and the same on the right).
But since their map doesn’t contain any walls, you won’t even need a pathfinding system here, you can just make the npc walk directly to the part using humanoid:MoveTo() (I think).
If you really want them to move randomly on your floor, you can try this :
- Get the minimal and maximal value for your x coordinate where the npc can go
- Do the same for the z coordinate
- Get the y coordinate of where your npcs walk (y)
- Generate 2 random numbers : first one (x) being between x_min and x_max, second one (z) being between z_min and z_max.
- Create a part (or use an existing one) that’s invisible and place it at the coordinates (x,y,z)
- Make the npc walk to this part
What you can understand from this logic is that the part is on the floor (y coordinate), and in a delimited zone (rectangular, between x_min, z_min, and x_max, z_max). This would make the movement really random.