Good 2D Collision Response References
Asked Answered
H

7

21

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)

Haskins answered 15/7, 2010 at 0:13 Comment(1)
Sorry, we can't migrate to stackexchange sites. But if you can access them (is gamedev in beta?) you can just ask the question over there.Vernonvernor
G
17

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

Gastongastralgia answered 23/8, 2010 at 4:29 Comment(1)
I find this C# version to be a better resource. The tutorial goes more in depth about projecting a polygon onto an axis, which I find the N tut misses. If anyone has any confusion from the N tut, check out this C# one.Haskins
D
3

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

Deactivate answered 15/7, 2010 at 0:21 Comment(0)
D
2

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, )\
Damarisdamarra answered 24/8, 2010 at 7:23 Comment(0)
M
1

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?

Melodious answered 18/8, 2010 at 16:29 Comment(1)
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.Haskins
M
0

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

Meso answered 17/5, 2013 at 9:25 Comment(0)
E
-1

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.

Ednaedny answered 16/7, 2010 at 17:49 Comment(1)
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.Haskins
P
-3

Have you looked at Cocos2d?

Penner answered 23/8, 2010 at 20:8 Comment(3)
I have heard of it. What's it do collision wise? Also, not really what I'm looking for, but thanks :)Haskins
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.)Penner
cocos is for apple products, not XNABlistery

© 2022 - 2024 — McMap. All rights reserved.