Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Region has to be aligned to the grid (use Region3:ExpandToGrid)?

Asked by
Vexture 179
8 years ago
Edited 8 years ago

so i intend to create a perlin noise terrain generator. i've never worked with terrain before, but i was looking around on the wiki and discovered :FillRegion() function for terrain, which takes 3 arguments:

:FillRegion(Region3 region, float resolution, Material material

well, that's all fine and dandy. i understand that Region3 takes two arguments, the first one being a minimum Vector3 value defining one corner of the region and a maximum defining the opposite corner.

resolution confuses me a little bit, but i set it to 4 because the output complained and said that the resolution had to be 4.

material is straightfoward enough

the problem is the error you saw in the title, Region has to be aligned to the grid (use Region3:ExpandToGrid). i've got no clue how im supposed to use Region3:ExpandToGrid or why i need to use it.

here's my code btw:

sea_level = .5
origin = 0
size = 1200
region = Vector3.new(origin-size,sea_level-12,origin-size),Vector3.new(origin+size,sea_level,origin+size)

--terrain generation
local terrain = workspace.Terrain
workspace.Terrain:FillRegion(Region3.new(region),Region3:ExpandToGrid(4),Enum.Material.Water)

so pretty straightforward, i don't understand how im supposed to use region3:ExpandToGrid. any ideas?

hope i explained my situation well enough. :^)

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Note: I have no experience using both of these functions, this is purely from wiki interpretation.


Explanation

I believe :ExpandToGrid() is the correct function, as it is described as "[a function that] expands the Region3 so that it is aligned with a voxel grid based on the provided resolution and returns the expanded Region3."

From this, it appears that the title is a bit misdirecting, as it is really aligning (not so much expanding) the Region3 to what I believe to be a Terrain compatible grid.

So, to put it simply, your answer is: Yes, :ExpandToGrid() should work.


How do you use ExpandToGrid?

All you need to do is perform the method on the Region3 you have defined, providing a resolution (I don't know exactly what that is, sorry). Then, :FillRegion() should, in theory, work:

local reg3 = Region3.new(Vector3.new(),Vector3.new())
local res = 4
reg3:ExpandToGrid(res)
game.Workspace:WaitForChild("Terrain"):FillRegion(reg3,4,Enum.Material.Water)

As a side note;

Defining region as two values will only make it the first value. If you would like to set one value to many, consider putting it into a table, then unpack()ing it when you want to use it:

local region = {Vector3.new(),Vector3.new()}
local reg3 = Region3.new(unpack(region))

http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions&redirect=no#unpack


Hope I helped!

~TDP

0
ty, that worked; i defined the original region as reg and then defined region as reg:ExpandToGrid(4), that resolved my issue. i appreciate it :^) Vexture 179 — 8y
Ad

Answer this question