Sign in to follow this  

2D Tank Game: collision detection among moving objects

This topic is 4071 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4071 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this