Take the 2-minute tour ×
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
    
Duplicate? gamedev.stackexchange.com/questions/25872/… –  Byte56 Jan 26 '13 at 22:18
    
@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 '13 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 '13 at 22:48
    
@Qqwy yes. the terrain is rendered by connecting a series of vertex. –  Truman's world Jan 26 '13 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 '13 at 18:21
show 4 more comments

1 Answer

You dont really need to do collision detection with the floor, since its expensive to calculate and im guessing the tanks are always touching the ground. All you need to do is to make the tanks height position equal to the one from your height index array. it will give the impression that the tanks are touching the floor but you are not actually calculating collision

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.