Hi, I am making a game, a survival game, where the players are in a Jurassic Park-like dinosaur theme park on an island. There are lots of cages/exhibits that hold NPC (non-player characters) dinosaurs that end up escaping their exhibits and the players have to survive for five minutes without the dinosaurs killing them (by touching/biting them, for most dinosaurs it takes multiple hits to kill the player but for one it only takes one hit). The problem is, I want the dinosaurs, after escaping their cages, to walk around the island until they find a player. Once they find a player within a certain range they can chase the said player and try to kill them. The following part is fine, I have got that working but the issue is with the walking around the island part. I have looked on Roblox and the Roblox wiki and read about NPC movement but all I could find is how to make it walk from one point to another or on a pathway from one point to another. If worst comes to worst I can maybe deal with making the dinosaurs travel on a pathway across various areas on the island but I am worried that if I do that then the players might realize the dinosaurs are following a path and then they will easily be able to avoid those paths. Because of this I REALLY need the dinosaurs to just walk randomly around the island until a player comes within range. Does anybody know a way that I can do this? And if it isn't possible, does anyone know how I can make the dinosaurs travel the island in as random a way as possible?
Thank you so much for your help, Skyraider5
Put this in the NPC you are tying to function. Make sure that this code is in a regular script.
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 25 -- Change this if you want the NPC to detect you further out. local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while true do wait(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
This should work. If this worked, please accept this answer.