# Get slope and color/texture at point on terrain

Can I get properties of a specific point (e.g. at mouse cursor) of the terrain?

I would like to implement mining into my game. And rather than use lots of manually defined spots, I would like to test if the point on which I clicked has a steep slope and if it has a texture “Rock” or is greyish etc.

Is that possible? I would imagine, this would ease our world building a lot.

Other solutions are welcome, if they are easier than manually define thousands of mining spots.

I already know how to get the world coordinates of the point on which was clicked, btw.

Terrain terrain = (Terrain) GetComponent(typeof(Terrain));
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (collider.Raycast(ray, out hit, 100f)) {
Vector3 terrainLocalPos = terrain.transform.InverseTransformPoint(hit.point);
Vector2 normalizedPos = new Vector2(Mathf.InverseLerp(0.0f, terrain.terrainData.size.x, terrainLocalPos.x),
Mathf.InverseLerp(0.0f, terrain.terrainData.size.z, terrainLocalPos.z));
float steepiness = terrain.terrainData.GetSteepness(normalizedPos.x, normalizedPos.y);
if (steepiness > 60f) {
Vector2 alphamapPos = new Vector2(normalizedPos.x * terrain.terrainData.alphamapWidth,
normalizedPos.y * terrain.terrainData.alphamapHeight);
float[,] alphamap = Terrain.activeTerrain.terrainData.GetAlphamaps((int) Mathf.Round(alphamapPos.x), (int) Mathf.Round(alphamapPos.y), 1, 1);
Debug.Log("alpha " + alphamap + " " + alphamap.GetLength(0) + " " + alphamap.GetLength(1));
float rockiness = alphamap[0, 0, alphamapLayerRock];
if (rockiness > 0.5f) {
// Mining okay
}
}
}

tneshi’s answer relies on you knowing the index of the alphamap layer that contains your rock texture. If you don’t already know that, you can programmatically determine it by going into `Terrain.terrainData.splatPrototypes`. That’s an array of `SplatPrototype`, each of which has a `texture` property and it’s in the same order as the alphamap layers.