Members - Reputation: 154
Posted 01 February 2012 - 05:00 PM
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?
Crossbones+ - Reputation: 7561
Posted 01 February 2012 - 05:32 PM
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.
The voices in my head may not be real, but they have some good ideas!