this uses the non perlin “wander towards” technique from the video using a start and endpoint that could easily be randomly generated
code for 1st and 2nd image (in serverscriptservice or workspace)::
local goal = Vector3.new(math.random(-500,500), 0, math.random(-500,500))
local start = Vector3.new(math.random(-500,500), 0, math.random(-500,500))
local function createPart(pos)
local part = Instance.new("Part")
part.Position = pos
part.Anchored =true
part.CanCollide =false
part.Size = Vector3.new(20,20,20)
part.Parent = workspace.Garbage
return part
end
local lastPos = start
local posTable = {}
local i=0
local lastUnit = Vector3.new(1,0, 0)
local seed = math.random(1, 279879)
local function getPos()
local dir1 = CFrame.fromAxisAngle(Vector3.new(0,1,0), math.rad( math.random(-90,90) )):VectorToWorldSpace(lastUnit)
local dir2 = CFrame.fromAxisAngle(Vector3.new(0,1,0), math.rad( math.random(-90,90) )):VectorToWorldSpace(lastUnit)
local towardsGoal = CFrame.lookAt(lastPos, goal).LookVector
local directions = {dir1, dir2, towardsGoal, dir1, dir2}
local nextUnit = directions[math.random(1,#directions)]
local newPos = lastPos +( nextUnit * 15)
lastUnit = nextUnit
if newPos == lastPos then
return getPos()
else
return newPos
end
end
while true do
task.wait()
local newPos =getPos()
--workspace.Terrain:FillBlock(CFrame.new(newPos), Vector3.new(20,20,20), Enum.Material.Water)
createPart(newPos)
if (newPos - goal).Magnitude < 10 then
break
end
lastPos = newPos
end
–
this is one using the worm method again from a start point to end point
code for the 3rd image (in serverscriptservice or workspace):
local goal = Vector3.new(math.random(-500,500), 0, math.random(-500,500))
local start = Vector3.new(math.random(-500,500), 0, math.random(-500,500))
local function createPart(pos)
local part = Instance.new("Part")
part.Position = pos
part.Anchored =true
part.CanCollide =false
part.Size = Vector3.new(10,10,10)
part.Parent = workspace
return part
end
local lastPos =start
local posTable = {}
local i=0
local lastUnit = Vector3.new(1,0, 0)
local seed = math.random(1, 279879)
local function getPos()
local towardsGoal = CFrame.lookAt(lastPos, goal).LookVector
local dir1 = CFrame.fromAxisAngle(Vector3.new(0,1,0), math.rad(math.clamp( (math.noise(lastPos.Magnitude,0,seed) * 800),-45,45 ) ) ):VectorToWorldSpace( (lastUnit+towardsGoal).Unit )
local directions = {dir1}
local nextUnit = directions[math.random(1,#directions)]
local newPos = lastPos +( nextUnit * 10)
lastUnit = nextUnit
if newPos == lastPos then
return getPos()
else
return newPos
end
end
while true do
task.wait()
local newPos =getPos()
--workspace.Terrain:FillBlock(CFrame.new(newPos), Vector3.new(20,20,20), Enum.Material.Water)
createPart(newPos)
if (newPos - goal).Magnitude < 10 then
break
end
lastPos = newPos
end
edit:: the first one can be easily locked to a grid like your original map is