Hey, I'm currently looking for various methods of implementing collision response in 2D video games, something similar to this tutorial Metanet has: N Tutorial I'm looking to implement something in XNA, but any language would be fine. I'm more interested in implementing programmatically than actual theory. I'd prefer more beginner friendly material, but I do welcome more advance topics.
So could someone suggest some good 2D collision response articles/books?
(PS: I'm more interested in response than detection)
One of the simpler forms of collision detection is between two rectangles that are axis aligned — meaning no rotation. The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles. Any gap means a collision does not exist.
A hitbox is an invisible shape commonly used in video games for real-time collision detection; it is a type of bounding box.
Quadtree is a way of partitioning space so that it's easy to traverse and search. A quadtree recursively partitions two-dimensional space into squares, dividing each square into four equally-sized squares. Each distinct data point exists in a unique leaf node; Coincident points are represented by a linked list.
AABB stands for axis-aligned bounding box , a rectangular collision shape aligned to the base axes of the scene, which in 2D aligns to the x and y axis.
The N tutorial that you mentioned already is a great resource to start with. I also recommend the very good article 2D Polygon Collision Detection. It comes with a great C# implementation and example for polygon collision detection using the Separating Axis Theorem and explains some of the concepts better.
As far as responding to a collision is concerned it depends on the scenario. For games you might want to check for a possible collision based on the current velocity and then simply adjust the actual velocity to prevent collision. You could also implement some sort of 'bounce' effect. In any case it will likely be adjusting both the velocity and direction of the object.
You can use the Separating Axis Theorem to do the collision detection and also use polygon projection to find the distance to the target on a specific axis. (most of the time the vector on which you move).
I really like this one, it just arrived a week ago and it's everything you could want short of doing relativistic effects:
http://www.amazon.com/Physics-Game-Programmers-Grant-Palmer/dp/159059472X
How much detail do you need? Answering some of these questions would help you eliminate packages that don't do what you need.
Do you have to worry about object rotation? Then you need to be concerned about lever arms, angular momentum, moments of inertia, and torques.
Do you have to worry about deformation? Then you need to get into finite element analysis, stress/strain, etc. -- something that describes how the objects respond internally to external forces.
What about frictional effects? Then you'll need coefficients of friction, or possibly velocity models for air resistance.
Gravitational effects? Electromagnetic effects? Other forces?
If you want a basic answer for collision response, here it is :
for each pair of objects that collide
ask gently to the collision detection lib their interpenetration distance
Apply an impulse (i.e. a force in the duration of the frame) to both objects :
force proportional to penetration depth (you will have to tune the coef by hand)
direction : perpendicular to the collision normal.
application point : the collision point (approximately, since it s not a point anymore but a volume)
integrate (Euler, Verlet, )\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With