Manually placing terrain details offset

Hey there,

I’m stuck on this part for a long time now, and couldn’t find a proper answer online. So I come to you guys in the hope someone can help me with this.

Situation:
I want to place terrain details (grass, etc.) on the terrain in runtime.

Problem:
The placing terrain details on the terrain part worked. The only problem is that I cant properly translate the values I put into the SetDetailLayer() function.

Example code:

for(i = 0; i < 7; i++){
		var test2 : int[,] = new int[2,2];
		test2[0,0] = 10;
		test2[0,1] = 10;
		test2[1,0] = 10;
		test2[1,1] = 10;
	
		terrainDA.SetDetailLayer (i*2, i*2, 0, test2);
	}

Example picture:
With the example code, and cubes with a size of (4,1,4) generated on the following positions; [(2,2), (6,6), (10,10), (14,14), …], I get you can see in the example picture below.

As you can see I can place the grass, but It isn’t placed where I want it to be. It’s just a bit off, but on a large terrain that can be crucial. Does anybody know where I went wrong?

Thanks for reading!

And yes, I know the dangers of using non supported functions.

Sources:
SetDetailLayer

If its in the docs, its supported!

I can make a guess. The Detail layer has a resolution, could be 512x512, could by any other number. The terrain has a size could be 600x600.

The details is stretched to cover the size of the terrain. So the far corner of tile (511,511) is at 600,600 in world space. That means if you want to place grass around 300,300 you should place grass at 255,255 - 256,256 on the detail layer.

You can set these numbers with the Terrain|Set Resolution dialog. You can only set Detail Resolution to powers of 2. So if you want the terrain to be aligned with world coordinates you need to make the terrain size a power of two (+1) to match.

I hope this helps.

Wow, yes that does help. Thanks a lot!