I made a script that generates smooth 2D terrain. The way it works is, every 8 units we generate a random value, and a part. In-between each random value we make parts that are interpolated to make it look like 2D Terrain:
-- Settings
local noiseScale = 8
local amplitude = 10
local mapSize = 512
-- End of settings
local permutations = {}
for x = -mapSize / 2, mapSize / 2, noiseScale do
permutations[x] = (math.random(0, 256) / 128) - 1
end
for x = -mapSize / 2, mapSize / 2, noiseScale do
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Parent = workspace
part.Size = Vector3.new(1, (permutations[x] + 1)*amplitude, 1)
part.CFrame = CFrame.new(x, 0 + (part.Size.Y / 2), 0)
end
function interpolate(x,y,alpha) --simple linear interpolation
local difference=y-x
local progress=alpha*difference
local result=progress+x
return result
end
for x = -mapSize / 2, mapSize / 2 do
if x % noiseScale > 0 or x % noiseScale < 0 then
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Parent = workspace
local a = 0
local b = 0
local c = 0
for i = x - noiseScale, x do
if i % noiseScale == 0 then
a = permutations[i]
break
end
end
for i = x, x + noiseScale do
if i % noiseScale == 0 then
b = permutations[i]
break
end
end
for i = x - noiseScale, x do
if i % noiseScale == 0 then
c = (x - i) / (noiseScale - 1)
break
end
end
local value = 0
value = interpolate(a, b, c)
part.Size = Vector3.new(1, (value + 1)*amplitude, 1)
part.CFrame = CFrame.new(x, 0 + (part.Size.Y / 2), 0)
end
end
The only issue is, it’s kinda “trianglish” Like look:
Sorry, I didn’t look at the code. I guess it would suffice to create several pieces, wouldn’t it? Creating parts between parts, that’s the true meaning of tween and that’s what tween service does. So, for me creating more parts should be enough (e.g. if you have a part at position {0,0,0} and you have a part at position {10,0,0}, then just create a part at position {5,0,0}. This sounds at the beginning only nonsense and senseless, but you can continue this practically purely theoretically on the infinity, so more parts, more beautiful)
I’m sorry, but this is too much for me. Still, I hope I helped you. But really click on the links. Tweening is when you make multiple copies of the same object Said by me it sounds weird, but if you really want to have something smooth like the TweenService does (and the TweenService is also used in many other places, like color changes. So you should always check it out first).
Cosine interpolation would be the one I should use because linear interpolation is triangle, but cosine interpolation is steeper in the middle, but at the top and bottom, it gets less steeper.
Cosine interpolation fixed the issue, I think I should also experiment with other interpolation options, thanks your your help @nicemike40, you too @Eternalove_fan32.
So what you’re really asking for is something like adding a fillet to your lines.
That’s some fun math if you don’t wanna do the easy way
Here’s something you can follow to calculate where a circle of radius R would sit nestled between two lines. That’s the bulk of the work, you can probably figure out how to apply that to your situation.