Some information on Terrain Collision wanted.

Hi, I’m making my own terrain data and I want to apply collision data to it.
I have it sort of working, but I need some more info. Can anyone help?

I realised that the height data needs to be in the 0-1 range and the scale is the ‘size’ Vector3.

But I don’t know the orientation of the terrain or the order the terrain vertices are in, or whether the position is the centre of the terrain or a corner?
I don’t know if needs rotating, but I have tried every angle there is, and it’s seems to be off by quite a bit.
My patches are 65x65 is size.

What I really want is a way of Rendering the Terrain Collision triangles.

Thanks,
Dave H.

For each patch I do…

coll = GetComponent<TerrainCollider>();
coll.terrainData = new TerrainData();
coll.transform.position = transform.position;     // Is this the centre or an edge?
coll.terrainData.heightmapResolution = widthGrid;   // 65x65 
coll.terrainData.size = new Vector3(patchWidth, 80.0f, patchWidth);
heights = coll.terrainData.GetHeights(0, 0, (int)widthGrid, (int)widthGrid);

// Later...

int i = 0;
for (int z = 0; z < widthGrid; z++)
{
	for (int x = 0; x < widthGrid; x++)
	{
		float h = vertices[i].y / 80.0f;
		h = Mathf.Clamp(h, 0.0f, 1.0f);
		heights[x, z] = h;
		i++;
	}
}
coll.transform.position = transform.position;
coll.terrainData.SetHeights(0, 0, heights);
coll.terrainData.physicMaterial = null;

Not quite sure what you’re asking. The terrain collider is a special heightmap collider in PhysX; you don’t compute vertices or anything. When you use SetHeights, the terrain/heightmap collider is updated with the new heights.

–Eric

I’m not using the built in Terrain objects. I’m creating my own fractal terrain, that has thousands of miles worth of patches.
I have game-objects rolling around on it with a TerrainCollider, but they are not in the correct place. I think I’ve discovered that the terrain starts at the ‘transform.position’ minimum corner, rather than that being the centre. But there doesn’t seem to be much info on anything else.

OK, I have it working now. I had to swap the X and Z coordinates around and put the ‘transform.position’ at the lower left X Z position of each rendered mesh