Best way to check which terrain im over?

I have 4 terrain tiles in my scene, and im trying to get the height where im over so I used:

terrHeight1 = Terrain.activeTerrain.SampleHeight(objpos.transform.position);

This i thought worked untill I noticed it would go to 0 which I new was wrong, what I did realise is it was only working on 1 terrain tile (the main one).

So what I need to do is check which terrain im “over” before I do the SampleHeight?

how do I do this?


Use raycasting to check which terrain is under the player. With the example at the bottom there you will get the hit object stored in the RayCastHit variable and then you can check if the object hit has a terrain on it with GetComponent. Make sure the terrain has a TerrainCollider or the raycast can not hit it.