问题
I want to write a platform game, all I done before was puzzle games with no need of physics.
All I need is simple collision detection, what I will supply the physics engine is position of all objects and it should output:
- All objects of a specific object type (bullets) that collide with any object (and what object), just a list of pairs.
- For every object of a specific object type (players and npcs) if its on ground or in mid air.
All the simulation of move/speed/gravity/hits/reflections will be done using custom code because what I want to implement is a world with strange physics.
Should I roll my own engine? can I use existing ones like chipmunk/box2d? If I need to implement my own how will I make collision detection not a costly operation? (like a naive implementation of just checking everything in O(n^2)
.
I can use objective-c or c++, I would prefer c++ (it should have better performance).
回答1:
If you are writing your own physics you probably want to include your own collision detection. There are also some publicly available free physics engines that you might try like bullet. (http://www.bulletphysics.org)
But you might want to just do a google search for collision detection algorithms that might apply to the kind of game you are making with the kinds of intersections you need to test for.
Here is an article I found at random: http://www.gamespp.com/algorithms/collisionDetection.html
回答2:
For this kind of problem, I'd recommend you write your own library.
Yes, you can find this kind of feature in existing libraries, however you'll learn a lot more from writing your own.
I recommend looking into graph and tree data structures.
来源:https://stackoverflow.com/questions/8521356/simple-collision-detection