Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
@Byte56 I think we are asking different question, and that post didn't give solutions towards heightmap though the OP is asking about heightmap. – Truman's world Jan 26 at 22:31
With "its not flat, its polygon" you mean that the terrain is not built out of horizontal ground and vertical walls but out of diagonals between two different height points? – Qqwy Jan 26 at 22:48
@Qqwy yes. the terrain is rendered by connecting a series of vertex. – Truman's world Jan 26 at 23:05
1  
@Qqwy Yes, it is a way to go. However, the radius of the circle is not easy to determine because the angles between line segments are different. For instance, when the angle between two line segments is very small, the radius of circle should be small as well to achieve a satisfactory result; but when the small radius is also used in big angles, the result will not good. This means, doing good collision detection in small angles will result in bad collision detection in big angles, and vice verse. DESPITE THESE SMALL FLAWS, you method is very helpful! thanks a lot! – Truman's world Jan 27 at 18:21
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.