Jump to content
  • Advertisement
Sign in to follow this  
roby65

Top down shooter and bullet collisions

This topic is 2513 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

Hi,

i'm developing a 2d top down shooter and i implemented collisions using rects, and everytime something moves i test collisions with all the other rects.
The problem raised now that i have to add bullets to my game, my first approach was to get the points of the line of the bullet and test collision with every rect for every point of the line, but this is the worst implementation that i ever used.
What's the best approach for the bullet physic?

Roby

Share this post


Link to post
Share on other sites
Advertisement
You might want to look at line/line intersection tests, (check the line the bullet is making against each line of the bounding rectangle for the possible target objects)

Then remember these simple facts:
1) The fastest code you can write is code that isn't executed
2) Objects that are far from eachother will not touch eachother
3) circle/circle collision tests or AABB tests are faster than line/line test. (and thus it makes sense to perform a quick rough test using one of these before you do a more expensive and accurate test)
4) If you partition your objects based on their location (using for example a tree structure) you can avoid testing colissions against objects that are far away very easily.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!