Better way to build walls?

Please can someone offer me some ideas? I’m building a 100 x 100 x 5 box that’s acting as the level and the player is going to move around inside this box. At the moment I’m constructing the box from cubes but it takes about 30 - 40 seconds for it all to render before the player can start doing anything, performance is pretty slow and it maxes the CPU on my laptop.

Can anyone suggest a better way to construct walls? I don’t want the player to be able to interact with them at all, they are just a way to stop them leaving the ‘box’.

Thanks,

BoM.

A single box (or 5 boxes, bottom, left, right, front and back) should not take 30-40 seconds to instantiate. What else are you doing?

I’m creating each the floor, walls and ceiling in sections.

I’ve got a script with a function for each section and I call them in Start() 1 at a time.

Each function does something similar to the following:

//behind where player starts
function Wall1()

{
for (var y = 1.0; y < 5.0; y++) {
for (var x = 0.0; x < 100.0; x++) {
var cube = Instantiate(cube, Vector3 (x, y, 0.0), Quaternion.identity);
}
}
}

So, your making 500 cubes how many times?

I have it split up a bit.

I did the walls 100 x 5 (so yeah, 500 each) and there are four of those.

I think the ceiling is 50 x 50 and there are four of those too (10,000)

I did the floor smaller, 25 x 25 so there are 16 of those (10,000)

I was experimenting to see if creating the boundaries in smaller sections improved performance but it didn’t appear to.

Full script is:

function Start () {

Floor1();
Floor2();
Floor3();
Floor4();
Floor5();
Floor6();
Floor7();
Floor8();
Floor9();
Floor10();
Floor11();
Floor12();
Floor13();
Floor14();
Floor15();
Floor16();
Wall1();
Wall2();
Wall3();
Wall4();
Ceiling1();
Ceiling2();
Ceiling3();
Ceiling4();
}

//behind where player starts
function Wall1()

{
for (var y = 1.0; y < 5.0; y++) {
for (var x = 0.0; x < 100.0; x++) {
var cube = Instantiate(cube, Vector3 (x, y, 0.0), Quaternion.identity);
}
}
}

//in front of where player starts
function Wall2()

{
for (var y = 1.0; y < 5.0; y++) {
for (var x = 0.0; x < 100.0; x++) {
var cube = Instantiate(cube, Vector3 (x, y, 100.0), Quaternion.identity);
}
}
}

//left of where player starts
function Wall3()

{
for (var y = 1.0; y < 5.0; y++) {
for (var z = 0.0; z < 100.0; z++) {
var cube = Instantiate(cube, Vector3 (0.0, y, z), Quaternion.identity);
}
}
}

//right of where player starts
function Wall4()

{
for (var y = 0.0; y < 5.0; y++) {
for (var z = 0.0; z < 100.0; z++) {
var cube = Instantiate(cube, Vector3 (100.0, y, z), Quaternion.identity);
}
}
}

function Ceiling1() {
for (var x = 0.0; x < 50.0; x++) {
for (var z = 0.0; z < 50.0; z++) {
var cube = Instantiate(cube, Vector3 (x, 5.0, z), Quaternion.identity);
}
}
}

function Ceiling2() {
for (var x = 50.0; x < 100.0; x++) {
for (var z = 0.0; z < 50.0; z++) {
var cube = Instantiate(cube, Vector3 (x, 5.0, z), Quaternion.identity);
}
}
}

function Ceiling3() {
for (var x = 0.0; x < 50.0; x++) {
for (var z = 50.0; z < 100.0; z++) {
var cube = Instantiate(cube, Vector3 (x, 5.0, z), Quaternion.identity);
}
}
}

function Ceiling4() {
for (var x = 0.0; x < 50.0; x++) {
for (var z = 50.0; z < 100.0; z++) {
var cube = Instantiate(cube, Vector3 (x, 4.5, z), Quaternion.identity);
}
}
}

function Floor1() {
for (var x = 0; x < 25; x++) {
for (var z = 0; z < 25; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor2() {
for (var x = 25; x < 50; x++) {
for (var z = 0; z < 25; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor3() {
for (var x = 50; x < 75; x++) {
for (var z = 0; z < 25; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor4() {
for (var x = 75; x < 100; x++) {
for (var z = 0; z < 25; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor5() {
for (var x = 0; x < 25; x++) {
for (var z = 25; z < 50; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor6() {
for (var x = 25; x < 50; x++) {
for (var z = 25; z < 50; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor7() {
for (var x = 50; x < 75; x++) {
for (var z = 25; z < 50; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor8() {
for (var x = 75; x < 100; x++) {
for (var z = 25; z < 50; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor9() {
for (var x = 0; x < 25; x++) {
for (var z = 50; z < 75; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor10() {
for (var x = 25; x < 50; x++) {
for (var z = 50; z < 75; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor11() {
for (var x = 50; x < 75; x++) {
for (var z = 50; z < 75; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor12() {
for (var x = 75; x < 100; x++) {
for (var z = 50; z < 75; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor13() {
for (var x = 0; x < 25; x++) {
for (var z = 75; z < 100; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor14() {
for (var x = 25; x < 50; x++) {
for (var z = 75; z < 100; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor15() {
for (var x = 50; x < 75; x++) {
for (var z = 75; z < 100; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

function Floor16() {
for (var x = 75; x < 100; x++) {
for (var z = 75; z < 100; z++) {
var cube = Instantiate(cube, Vector3 (x, 0, z), Quaternion.identity);
}
}
}

hey a better way is to make a plane and rotate it so it is facing inwards

There’s no need to have all those separate functions, since they do basically the same thing. Also, since you’re not doing anything with the return value of Instantiate, there’s no need to assign it to a variable. Instead you can do

function MakeFloor (xStart : int, xEnd : int, zStart : int, zEnd : int, yValue : float) {
	for (x = xStart; x < xEnd; x++) {
		for (z = zStart; z < zEnd; z++) {
			Instantiate(cube, Vector3 (x, yValue, z), Quaternion.identity);
		}
	}
}

Although it’s kind of a moot point, since the best thing is to not instantiate zillions of separate objects, but construct a mesh (or several meshes) instead. The downside is that it’s quite a bit harder to do. There are some topics about doing MineCraft-style games, which have code that you could look at, since the idea is similar.

–Eric

I’d use a 3D model with a separated structure on the cube. Basically, one bone for each wall. That way you just need to scale the bones to shape and reshape the room. So long as you don’t have hundreds of them, it works just fine.

You’ll have to bear with me here because I’m very new to all this (as you can probably tell).

I did a quick Google for ‘Unity Mesh’ and I found this article in the Support section of Unity: http://unity3d.com/support/documentation/Components/class-Mesh.html. “You don’t build meshes in Unity, but in another application”.

So what you’re suggesting is to actually build the walls using 3D package and then import them in? Is that right?

What would people recommend as a starting point for learning how to do this? Which tool is best for a beginner (and preferably free because this is just a hobby).

If the level is meant to be the same every time (as opposed to procedurally generated), then yes, building it in another app would be definitely the way to go. Blender is free, and building levels like you seem to be doing (cubes) is pretty trivial with it.

–Eric

Great - thanks for the advice. I downloaded the 30 day trial of Lightwave because it seemed pretty simple to use from the video demo. If Blender is free I will give that a whirl too. Thanks to everyone who has posted on this thread - great help.

You can also build meshes in Unity… And honestly that is the best way to go. if everything were squared

I would build it in steps. Like walls, like floors, like ceilings. The only bad thing is that… its all alike.

You could also store prefab walls and floors and stitch them together. So say your wall is 30 units long, and you have 5 30 unit long walls. orientate it and place it. That takes the spot of 30 cubes, and once texture will look a thousand times better.

The only downside is that you have to have everything seamed, but that is not a huge deal. Assume that unit zero and unit 10 are the top and bottom. You are required to fill those two with vertices. On a wall, you build a 3d section that could wrap around the corner just a hair. So you build the geometry to make it look like that. Since the top and bottom units are filled and a polygon to make it look right then you can do anything else that you want with the space.