i am making a game with castle walls, made of separate cubes. The game works perfectly. but making a bunch of levels is very time consuming. there is a game similar to my game called toblo. their maps have millions of blocks and they use bitmaps.
they have used the blue Chanel for wall height, the walls goes from 1 to 255 and the only program they needed to use to make the maps is MS paint! this would make my job much easier if i could get a scrip preferably Java to generate my maps from a texture.
but i have absolutely no idea where to start
also will a game of 10,000 game objects with physics cause lots of lag
You could actually randomize the color on the castle bricks quite easy. first i would start by making 1x1 textures of every blue color. Then define all of them like this
var blueTex1 : Texture2D
var blueTex2 : Tex.... //etc
Once you have all 255, name all the blocks in your scene like so.
var wallBlock1 : GameObject;
Now for the random part say…
var randomSletector : int;
randomSelector = Random.Range(0,256);
if(randomSelector == 5)
{
wallBlock1.texture2D = blueTex5;
}
Now Something like this would work, but is going to be rather expensive, as randomization always is.
To answer your second question, yes 10,000 blocks would cause a lot of lag, espicially if they were falling over like dominos. 300, may run alright but if you have high polly object, or just high quality textures you would also experience some lag. Best thing to do is to bake animations.
Good Luck!
Here is a runtime script in C# (sorry not Javascript) as an example. You’ll likely have to convert it to a an editor script and make changes for your the nature of your game. The way I defined the input, all the input colors are multiplied by eight, so there are only 32 levels per color. This gave much better color variation when editing in Photoshop. I use red for the base level, then green for spaces (windows and doors), then blue on top. I used one pixel per column. I edited it in Photoshop zoomed in using the pencil tool set to 1 pixel. I imported the image with these settings: Advanced, Read/Write Enabled, Generate Mip Maps off, RGBA 32 bit format.
Here’s the input image:

And here is what it outputs:

public class WallBuilder : MonoBehaviour {
public Material mat;
void Start () {
StartCoroutine (ProcessImage ());
}
IEnumerator ProcessImage() {
Texture2D tex = Resources.Load ("Builder") as Texture2D;
Vector3 v3Start = new Vector3(-tex.width / 2.0f, 0.0f, -tex.height / 2.0f);
Color32[] arcolors = tex.GetPixels32();
for (int i = 0; i < tex.width; i++) {
for (int j = 0; j < tex.height; j++) {
Vector3 v3Pos = new Vector3(v3Start.x + i, 0.0f, v3Start.z + j);
BuildColumn(v3Pos,arcolors[i + tex.width * j]);
}
yield return 0;
}
}
Vector3 v3Scale = new Vector3(0.95f, 0.95f, 0.95f);
void BuildColumn(Vector3 v3Pos, Color32 c32) {
Debug.Log (c32);
if (c32.r == 255 && c32.g == 255 && c32.b == 255)
return;
float fHeight = 0.0f;
for (int i = 0; i < c32.r / 8; i++) {
GameObject go = GameObject.CreatePrimitive (PrimitiveType.Cube);
go.transform.position = new Vector3(v3Pos.x, fHeight, v3Pos.z);
go.transform.localScale = v3Scale;
go.renderer.material = mat;
fHeight += 1.0f;
}
fHeight += c32.g / 8;
for (int i = 0; i < c32.b / 8; i++) {
GameObject go = GameObject.CreatePrimitive (PrimitiveType.Cube);
go.transform.position = new Vector3(v3Pos.x, fHeight, v3Pos.z);
go.transform.localScale = v3Scale;
go.renderer.material = mat;
fHeight += 1.0f;
}
}
}