Saturday, January 11, 2014

Calculating Block Sizes for Surrounding a Uniform Pattern

Placement is on a 50 x 50 grid. (x,z)
Assume all blocks have a y factor of >0, and then forget about the y-axis.

Gap size will be 3.6364 units (based on a 40x40 grid split into 11x11 equal sections)


It doesn't generate walls here, so we make a uniform pattern
Purpose of all this:
We have a 40x40 pattern which uses uniform entrance and exit placement, which needs walls placed around it. We also need those patterns to snap to our 50x50 grid system to be generated and placed in the game world using a spawner. This is also how I created the buildings in my Alpha game, I simply made a bunch of patterns, instantiated them into the game world using a spawner script I wrote, and then generated a roof overhead using another spawner script I wrote. This allows the buildings to change every round, while still keeping a uniform to the placement. Simple stuff.


to calculate the size of blocks on the x-axis to gap
From the inside of the room everything looks fine

50(width) - 3.6(gap) = 46.3636 (space required)
46.3636 / 2(blocks) = 23.1818(block size)
23.1818 / 2 (position = size/2)
(+)11.5909 position from 0x


to calculate position of block from 50x side

50 - (+)11.5909 (total space - position)
(+)38.4091 position from 0x


From the outside, not so much; this is due to "normals"
to calculate the z size of x-axis blocks

50(length) - 40(playfield length) = 10 (space required)
playfield must be centered at (25x,25z) to be uniform
10 / 2(blocks) = 5(block size.z)


to calculate position of x-axis blocks on the z-axis

0z + 5(block size.z) / 2 (position = size/2)
(+)2.5 position from 0z


to calculate position of x-axis block from 50z side

50 - (+)2.5 (total space - position)
(+)47.5 position from 0z


to calculate the size of blocks on the z-axis to gap

50 - 10(2*5 (2 x-axis blocks with width of 5z) = 40
40 - 3.6364(size left - gap size) = 36.3636
36.3636 / 2 (size left / blocks) = 18.1818
18.1818 / 2 (position = size/2) = 9.0909
9.0909 + 5 (adjustment for x-axis blocks)
(+)14.0909 position from 0z


to calculate the position from 50z side

50 - (+)14.0909 (total space - position)
(+)35.9091 position from 0z


to calculate the x size of z-axis blocks

50(length) - 40(playfield length) = 10 (space required)
playfield must be centered at (25x,25z) to be uniform
10 / 2(blocks) = 5(block size.x)


to calculate position of z-axis blocks on the x-axis

0x + 5(block size.x) / 2 (position = size/2)
(+)2.5 position from 0x


to calculate position of z-axis block from 50x side

50 - (+)2.5 (total space - position)
(+)47.5 position from 0x

Now we have a perfect box, built around a uniform pattern. There are a ton of uses for this, you'll simply have to be creative enough to find them.

No comments:

Post a Comment