Jeff
Jeff

Reputation: 1213

Good 2D Collision Response References

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)

Upvotes: 21

Views: 29136

Answers (7)

Patrick Klug
Patrick Klug

Reputation: 14391

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

Upvotes: 17

grunge fightr
grunge fightr

Reputation: 1370

I was searching for same info too, The most usable thing i found so far was

http://www.myphysicslab.com/collision.html

the worse thing here for me is tahat this is withoout friction (tangent collision impulse only normal impulse) and I think the one with such friction impulse would be better but still not found a tutorial how to correctly implement that

Upvotes: 0

Calvin1602
Calvin1602

Reputation: 9547

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

Upvotes: 2

John
John

Reputation: 16007

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?

Upvotes: 1

deft_code
deft_code

Reputation: 59299

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.

Upvotes: -1

eruciform
eruciform

Reputation: 7736

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

Upvotes: 3

Related Questions