2D Tank Game: collision detection among moving objects

Started by
5 comments, last by NIm 17 years, 6 months ago
Hello all :) Tank game is my homework. It uses 2d graphics. My problem is detecting collisions among moving objects. Moving objects are tanks and bullets. There are many moving objects in a map. If using a list to contain moving objects, then checking collision in pair of objects, I think the performance will be bad. Do you have any solution else? Thank in advanced
Advertisement
Take the position of the pair of objects and their maximum velocity. This gives you a duration of non-collision between the two objects, which is more or less the distance between them divided by their relative velocity. Do not test the two objects for collision again before that duration runs out.

but the direction of a tank is changed frequently.
One option you have if you are really worried about performance is to sector up your map into cells - that way you only need to check entities against each other if they are in the same cell or a neighbouring cell.
ByronBoxes
Quote:Original post by Byron
One option you have if you are really worried about performance is to sector up your map into cells - that way you only need to check entities against each other if they are in the same cell or a neighbouring cell.


thank you, I'll try it.
Quote:Original post by realtiger
but the direction of a tank is changed frequently.


Your tank speed is probably smaller than a fixed value, so regardless of the direction it moves in the collision will not occur before the distance between bullet and tank has been traversed by both.

Also, check objects for proximity first: if they are not within radius + velocity/lengthofoneframe, then it's impossible that they collide, so don't check that collision.

This topic is closed to new replies.

Advertisement