I have a path generator that uses Bezier curves. it generates fine but when there’s water in the path of the road it just cuts off.

How can I make the path generator generate paths around the edges of the water?

```
local module = {}
function getPascal(size)
local row = {1}
if size > 1 then
for i = 2,size do
local newrow = {}
for x = 1,i do
if x == 1 or x == i then
newrow[x] = 1
else
newrow[x] = row[x-1] + row[x]
end
end
row = newrow
end
end
return row
end
function getPosition(t, perc)
local inv = (1-perc)
local result = Vector3.new(0,2500,0)
local SIZE = #t
local pasc = getPascal(SIZE)
for i, pos in pairs(t) do
result = result + pos * inv^(SIZE - i) * perc^(i-1) * pasc[i]
end
return result
end
function module:Generate(A,B,ammount,roadsegments,offsetammounts)
local t = {A}
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {workspace.Terrain}
raycastparams.FilterType = Enum.RaycastFilterType.Whitelist
for i = 1, roadsegments do
local newPos = A + (B - A).Unit * i * (B - A).Magnitude / roadsegments
local offset = Vector3.new(math.random(-offsetammounts, offsetammounts), 0, math.random(-offsetammounts,offsetammounts))
if i == 0 or i == roadsegments then
offset = Vector3.new(0, 0, 0)
end
newPos = newPos + offset
table.insert(t, newPos)
end
for i = 0,ammount do
local ray = workspace:Raycast(getPosition(t, i/ammount), Vector3.new(0,-5000,0), raycastparams)
if ray then
local min = ray.Position - (0.5 * Vector3.new(10,50,10))
local max = ray.Position + (0.5 * Vector3.new(10,50,10))
local region = Region3.new(min, max)
workspace.Terrain:ReplaceMaterial(regi on, 4, Enum.Material.Grass, Enum.Material.Mud)
workspace.Terrain:ReplaceMaterial(region, 4, Enum.Material.Snow, Enum.Material.Mud)
workspace.Terrain:ReplaceMaterial(region, 4, Enum.Material.Rock, Enum.Material.Mud)
workspace.Terrain:ReplaceMaterial(region, 4, Enum.Material.Sand, Enum.Material.Mud)
end
end
end
return module
```