Terrain Generation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
(cats)
>Mindraker
No edit summary
Line 3: Line 3:
== Terrain Generation ==
== Terrain Generation ==


First, the way the terrain looks is based off of a number of points, either set randomly or by the user. The terrain genarator will try to drag the land upwards or downwards based on the height and position of these points, which I will refer to as "nodes".  
First, the way the terrain looks is based off of a number of points, either set randomly or by the user. The terrain generator will try to drag the land upwards or downwards based on the height and position of these points, which I will refer to as "nodes".  


When generating the terrain, the terrain generator will go through every part, in the list of parts being worked with, and do the following routine for it:
When generating the terrain, the terrain generator will go through every part, in the list of parts being worked with, and do the following routine for it:
Line 29: Line 29:


this probably won't make a very nice thing though, it will curve too sharply, getting it just right is quite finicky.
this probably won't make a very nice thing though, it will curve too sharply, getting it just right is quite finicky.
== Mathematically generated terrain ==
[[Image:Complexterrain1.PNG|thumb|x*e^-(x^2+y^2)]]
Complex terrain can be created with mathematical formulas.  One problem with this, however, is the number of bricks that this entails.  Notice the smooth hills and valleys in the above picture - the picture was taken from a side view.
<pre>
for i = -2,2, .1 do
for j = -2,2, .1 do
y=i*(math.exp(1))^-((i^2)+(j^2))
p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*i, 100*y, 100*j))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26) -- change this to whatever color you want
end
end
</pre>


[[Category:Scripting Tutorials]]
[[Category:Scripting Tutorials]]

Revision as of 19:02, 29 December 2008

Terrain Generation

First, the way the terrain looks is based off of a number of points, either set randomly or by the user. The terrain generator will try to drag the land upwards or downwards based on the height and position of these points, which I will refer to as "nodes".

When generating the terrain, the terrain generator will go through every part, in the list of parts being worked with, and do the following routine for it:

{ for each of the nodes do the following:

1) check the distance from the node to the current part.

2) make a modifier, based on the distance, such as the modifier being the distance/10.

3) then if the part is below the node, subtract the modifier from it's vertical size, or if it's above add to it. }

The farther away the point is from the nodes(s), the less it will be changed, resulting in a perfectly sloped surface.

But, this is just a simplified version, making the landscape's slope curved is a bit more tricky.

Giving you a hint, it might be something like this:

d = The distance between the node and the part being modifed m = the amount the part will be modified by

m = d^(10/d)

this probably won't make a very nice thing though, it will curve too sharply, getting it just right is quite finicky.

Mathematically generated terrain

x*e^-(x^2+y^2)

Complex terrain can be created with mathematical formulas. One problem with this, however, is the number of bricks that this entails. Notice the smooth hills and valleys in the above picture - the picture was taken from a side view.

for i = -2,2, .1 do
for j = -2,2, .1 do

y=i*(math.exp(1))^-((i^2)+(j^2))

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*i, 100*y, 100*j))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26) -- change this to whatever color you want

end
end