views:

235

answers:

6

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)

+2  A: 

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

eruciform
+2  A: 

Physics engines are very complicated. You would be much better off using an existing one.

  • Farseer (C#, derived from an older version of Box2D).
  • Box2d (C++, It has .NET bindings)
  • Chipmunk (C, I don't think it has a C# port, but you could make one).

If you want to use physics in your game, use Farseer, or a Box2D bindings. If you want to learn about physics, consider making C# port of Box2D, or Chipmunk. If you are just curious, all of their code is open source.

caspin
I'm less interested in doing realistic physics and more interested in how you deal with the actual collision (like how N uses projection). I guess what I'm looking for is the bare bone basics, nothing complicated. I have looked at Box2D and heard of Farseer, and they do look pretty good and I'd definitely resort to one or the other if I decided to make a physics based game. Box2d is on Flash as well.
Jeff
+1  A: 

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?

John at CashCommons
I literally just want basic response. Some tutorial that implements something like Mario 3 for example would be fine (although the New Mario has some pretty fun physics...). I want to know what they do to respond to collisions. Do they produce a minimum correction vector and move out? Do they use little springs? But most importantly I'm looking for HOW they implemented this. The N tutorial I posted is pretty close to what I'm looking for, but I'd rather something more in depth.
Jeff
+4  A: 

I searched for this a year ago and the N tutorial was by far the best resource I could find. Check out this article for a C# implementation and example of polygon collision detection using the Separating Axis Theorem.

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).

Patrick Klug
This is excellent!
Jeff
You are welcome!
Patrick Klug
+1  A: 

Have you looked at Cocos2d?

Intro to Cocos2D Tutorial

Intro to Box2D Tutorial

How to Create a Breakout Game with Box2D and Cocos2D Tutorial: Part 1/2

How to Create a Breakout Game with Box2D and Cocos2D Tutorial: Part 2/2

-Waldo

gWaldo
I have heard of it. What's it do collision wise? Also, not really what I'm looking for, but thanks :)
Jeff
I'm not sure what environment that you're developing in, but Cocos2d can be used for the Mac and iPhone, but I'm not sure what else it can be used for (if any.)
gWaldo
A: 

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, )\
Calvin1602