Okay, I have some procedurally generated terrain (based loosely on http://www.swiftless.com/terraintuts.html)
Ive got a teapot “plane” which you can fly around in (third person camera)
Basically, the aim is to fly through the valleys etc… without crashing.
What I cant work out is how to calculate whether you have collided with the terrain or not?
Any ideas?
A terrain map is particularly easy to test for collision against, since a terrain map is a map from a 2d point (x, y) to the height of the terrain, TERRAIN[x, y] at that point. Given your teapot plane at (t_x, t_y, t_z), just test its height against the height of the terrain at (t_x, t_y). That is, if t_z < TERRAIN[x, y], then you’ve crashed. You can test multiple points (perhaps the corners of a cube centered at the center of the teapot) against the terrain to give a more accurate result. Depending on the coarseness of your terrain map, you might pick a nearby grid-point, or interpolate linearly to compute the height of the terrain at an arbitary point.