Hello! I am Hunter and I am creating a large scaled map that will generate randomly based on a script. I am wondering if anyone could explain the best possible way to do this and how to use the diamond square algorithm with it. Wikipedia does not have the best items of information for support so I am turning to the DevForum. If anyone could help me, that would greatly be appreciated.
Uhh are you trying to generate a random map for every server? There are plenty of tutorials on the web (mostly videos). I haven’t watched all of them, but I recommend Eppobot’s random terrain generating video.
And, you don’t really have to use the Diamond Square Algorithm. There are already pre-written code for it, just use them . (I think there is a random terrain generate option in the terrain editor in Roblox Studios, but I don’t think it can be intergrates with a script)
Check out some of the links at the bottom of the wikipedia page
For example, there’s an example implementation in Lua with an MIT license! There’s also a link to a really nice explanation on both diamond-squares and the related midpoint displacement algorithms.
It’s fine to ask for help, but try reading up on the problem first from a few different sources. Apart from the stuff I linked, video tutorials and stackoverflow links are just a quick google away. If you have any specific questions, then it makes more sense it ask for help. So if you need help understanding a part of one of the explanations, let us know
I tested the Lua implementation linked to from wikipedia, and here's the terrain I generated with it:
Here's the script that does the generating
local DS = require(game.ServerStorage.DS
local size = 128
local power = 1.5
local map = DS(size, size, nil)
for x = 0, size do
for y = 0, size do
local height = map[x][y] * power
local hue = (height/30) % 1
local p = Instance.new("Part")
p.Anchored = true
p.Size = Vector3.new(1, 5, 1)
p.CFrame = CFrame.new(x, height, y)
p.Color = Color3.fromHSV( hue, 1, 1)
p.Parent = game.Workspace
end
end
If you want infinite terrain with this algorithm, you’ll have to somehow adapt it. I don’t think it’ll be super hard though. Check out these links I found by googling:
Thanks ya’ll. I apologize for not reaching out earlier, I was on my holiday vacation. I am making terrain generated with wedges only and am confused with understanding the generation. Thank you @ThanksRoBama for this though I am confused with how i should utilize wedges.
You’ll need to figure out how to generate a triangle between three 3D points. There’s lots of information on Google, or you can find some old versions of triangle terrain plugins in the toolbox and use their implementations.
Once you can generate a triangle between 3 points, you can generate a whole area of terrain by repeatedly generating square grid “cells”. Each cell is 4 points, so you’ll have to generate 2 triangles per cell. If you have a cell that starts at (x, z)
then the other 3 coordinates are (x + 1, z)
, (x, z + 1)
and (x+1, z+1)
. The y coordinates for these is simply found by looking up in the generated map.
Thank you for this explanation. I will use this greatly for my game.