- Home /
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?
Thanks Andy
Answer by GameVortex · Jan 10, 2014 at 12:12 PM
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.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Detect closest reachable point of object 1 Answer
Buttons - Multiple Referencing 0 Answers
Trying to tile terrain, encountering strange axis flipping 0 Answers
Making the player be sticked to the ground, help please! 1 Answer