franck22000 Posted April 21, 2011 Share Posted April 21, 2011 Hello I still have some difficulties to deal with terrain so here is my question. How can i get the terrain height at the camera position ? Do someone can give me a simple example code ? Thanks ! Quote You guys are going to be the death of me. Josh Link to comment Share on other sites More sharing options...
Flexman Posted April 21, 2011 Share Posted April 21, 2011 I found this function I used to pass a position and a sample height height that returns the terrain height as well as any mesh object above it. ' RETURNS Y AS GROUNDHEIGHT ' Function GetPointOnGround:TVec3(pos:TVec3 var, pickheight:Float = 0) Local retpos:TVec3; pos.y = TerrainElevation(TTerrain(game.scene.terrain), pos.x, pos.z) ; if (pickheight > 0) Local pick:TPick; pick = LinePick(Vec3(pos.x, pos.y + pickheight, pos.z), pos) ; if (pick <> null) pos.y = pick.y; End If End If retpos = pos; Return retpos; End Function This next bit of code is simpler, it returns the height ABOVE the terrain rather than the actual terrain height but you can see how it works easily enough to adapt. It relies that you have access to the terrain entity which is normally done through some scene processor function if you're loading it from a file. CamHeightAboveTerrain = MyCamera.Position.y - TerrainElevation(TTerrain(game.scene.terrain), MyCamera.Position.x, MyCamera.Position.z) ; Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.