Hello, I know the title sounds simple and that you can find it anywhere on the internet but I haven’t really found any method to this specific very simple request, which I find quite shocking.
I’m looking for an R6 NPC that wanders around the map aimlessly, like, with no math.random set destinations, no waypoint bricks, nothing fancy, just an NPC that wanders around the map, one that can even fall off the map if it has no borders.
I’ve seen a lot of these types of NPCs around games but personally I haven’t managed to make/find one exactly like them.
I have tried to script one but it just has that math.random preset destinations which just makes them walk to the random generated positions set in the brackets:
while task.wait(math.random(3,5)) do
local x = math.random(-15, 15)
local z = math.random(-15, 15)
script.Parent:MoveTo(Vector3.new(x,script.Parent.Parent.Head,z))
end
If anyone has any idea on how to actually make one of them, please don’t be afraid to leave a reply.
It is indeed very simple but I’m unsure wheter thats on the internet or not (im sure its hidden somewhere we both didn’t look):
you could try something like this:
----Variables:
local MapBounds = {Vector2.new(0,0),Vector2.new(100,100)} --x,y = x,z in 3d
local MaxHeight = 100
----Functions:
local function getHeightAtPoint(position : Vector2)
local Pos3D = Vector3.new(position.X,MaxHeight,position.Y)
local result = workspace:Raycast(Pos3D,Vector3.new(0,-1,0)*(MaxHeight*1.1),)
if result and result.Position then
return result.Position.Y
end
end
local function getRandomPosition()
local randX = math.random(MapBounds[1].X,MapBounds[2].X)
local randZ = math.random(MapBounds[1].Y,MapBounds[2].Y)
local height = getHeightAtPoint(Vector2.new(randX,randZ))
if not height then error("no height found") end
return Vector3.new(randX,height+1,randZ)
end
while true do
script.Parent:MoveTo(getRandomPosition())
script.Parent.MoveToFinished:Wait()
end
I did look for an NPC like I wanted because the devforum wasn’t my first choice to ask for something like this because it seemed way too easy of a question to be asked on here.
I tried your NPC script but they now are constantly on the move, I need them to just walk somewhere, stay there for a randomly generated amount of time and them be on the move again (my bad for not mentioning that in the topic).
They also seem to be doing the same thing as before, they just go to a set range of an x and y positions and just wander around that zone, hence I was able to capture all 10 NPCs that were spawned in the same picture after letting them wander for 2-3 minutes:
I don’t need the NPCs to jump, they should be fine walking around on a flat, not-so-deformed plain terrain.
Yet, thank you for trying to help me with this issue. If you have any updates, with the now mentioned details and issues that I provided in my reply, please let me know and I’ll try them out as well.
Its as simple as them either following preset paths or them just walking to a random point along a zone. You can’t do this in any game without setting paths and or destinations randomly or preset. They need some direction
I can’t send footage unfortunately but I’ll just use the preset math.random zones because I can’t really brainstorm how to find an actual fix to this. Thanks for the help though.