Collision detection with heightmap based terrain
- by Truman's world
I am developing a 2D tank game. The terrain is generated by Midpoint Displacement Algorithm, so the terrain is represented by an array:
index ---> height of terrain
[0] ---> 5
[1] ---> 8
[2] ---> 4
[3] ---> 6
[4] ---> 8
[5] ---> 9
... ...
The rendered mountain looks like this:
*
* * *
* * *
* * * *
* * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
0 1 2 3 4 5 ...
I want tanks to be able to move smoothly on the terrain (I mean tanks can rotate according to the height when they move), but the surface of the terrain is not flat, it is polygonal. Can anyone give me some help with collision detection in this situation?
Thanks in advance.