2D Collision Response 
Author Message
 2D Collision Response

I have been searching all over google, and gamedev.net, for a
straightforward method of introducing somewhat realistic collision responses
between circles (in 2 dimensions),

I cant just seem to get the elasticity / mass right... After reading
http://www.*-*-*.com/

I tried the following, but my objects sometimes bounce, sometimes hook on
each other.... any ideas on fixing this? or a better solution?

-----------------

'After determing whether or not a collision occured (between Ship(i) and
Ship(j))

                        '//Solve differences of velocities (B's velocity -
A's velocity)
                        D3DXVec2Subtract velocityDiff, Ships(j).vector,
Ships(i).vector

                        '//Solve collision normal
                        D3DXVec2Subtract collisionNormal, Ships(j).location,
Ships(i).vector
                        D3DXVec2Normalize collisionNormal, collisionNormal
'//Contains normalized collision normal

                        '//This was test code to see how the mass /
elasticity worked
                        Ships(i).mass = Ships(i).radius * 10 'radius is
between 5 and 10
                        Ships(j).mass = Ships(j).radius * 10

                        Ships(i).elasicity = 0.5
                        Ships(j).elasicity = 0.5

                        sngK = (1 + Ships(i).elasicity) *
D3DXVec2Dot(velocityDiff, collisionNormal) * (Ships(j).mass) /
(Ships(i).mass + Ships(j).mass)
                        D3DXVec2Scale impulse, collisionNormal, sngK

                        D3DXVec2Add Ships(i).vector, Ships(i).vector,
impulse

                        '//Now solve for j's ship, B Is I, and A is j now
                        '//Solve differences of velocities (B's velocity -
A's velocity)
                        D3DXVec2Subtract velocityDiff, Ships(i).vector,
Ships(j).vector

                        '//Solve collision normal
                        D3DXVec2Subtract collisionNormal, Ships(i).location,
Ships(j).vector
                        D3DXVec2Normalize collisionNormal, collisionNormal
'//Contains normalized collision normal

                        sngK = (1 + Ships(j).elasicity) *
D3DXVec2Dot(velocityDiff, collisionNormal) * (Ships(i).mass) /
(Ships(j).mass + Ships(i).mass)
                        D3DXVec2Scale impulse, collisionNormal, sngK

                        'D3DXVec2Add Ships(j).vector, Ships(j).vector,
impulse



Sun, 26 Dec 2004 03:26:11 GMT  
 2D Collision Response
How about phytagoras ??

Function Get2DDist(X1, Y1, X2, Y2,) As Currency
    Get2DDist = Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2 )
End Function

...

if Get2DDist(blabla) < Circle1Radius then BUM!



Quote:
> I have been searching all over google, and gamedev.net, for a
> straightforward method of introducing somewhat realistic collision
responses
> between circles (in 2 dimensions),

> I cant just seem to get the elasticity / mass right... After reading
> http://pub21.ezboard.com/fmrgamemakerfrm0.showMessage?topicID=2365.topic

> I tried the following, but my objects sometimes bounce, sometimes hook on
> each other.... any ideas on fixing this? or a better solution?

> -----------------

> 'After determing whether or not a collision occured (between Ship(i) and
> Ship(j))

>                         '//Solve differences of velocities (B's velocity -
> A's velocity)
>                         D3DXVec2Subtract velocityDiff, Ships(j).vector,
> Ships(i).vector

>                         '//Solve collision normal
>                         D3DXVec2Subtract collisionNormal,
Ships(j).location,
> Ships(i).vector
>                         D3DXVec2Normalize collisionNormal, collisionNormal
> '//Contains normalized collision normal

>                         '//This was test code to see how the mass /
> elasticity worked
>                         Ships(i).mass = Ships(i).radius * 10 'radius is
> between 5 and 10
>                         Ships(j).mass = Ships(j).radius * 10

>                         Ships(i).elasicity = 0.5
>                         Ships(j).elasicity = 0.5

>                         sngK = (1 + Ships(i).elasicity) *
> D3DXVec2Dot(velocityDiff, collisionNormal) * (Ships(j).mass) /
> (Ships(i).mass + Ships(j).mass)
>                         D3DXVec2Scale impulse, collisionNormal, sngK

>                         D3DXVec2Add Ships(i).vector, Ships(i).vector,
> impulse

>                         '//Now solve for j's ship, B Is I, and A is j now
>                         '//Solve differences of velocities (B's velocity -
> A's velocity)
>                         D3DXVec2Subtract velocityDiff, Ships(i).vector,
> Ships(j).vector

>                         '//Solve collision normal
>                         D3DXVec2Subtract collisionNormal,
Ships(i).location,
> Ships(j).vector
>                         D3DXVec2Normalize collisionNormal, collisionNormal
> '//Contains normalized collision normal

>                         sngK = (1 + Ships(j).elasicity) *
> D3DXVec2Dot(velocityDiff, collisionNormal) * (Ships(i).mass) /
> (Ships(j).mass + Ships(i).mass)
>                         D3DXVec2Scale impulse, collisionNormal, sngK

>                         'D3DXVec2Add Ships(j).vector, Ships(j).vector,
> impulse



Sun, 26 Dec 2004 04:09:36 GMT  
 2D Collision Response

Quote:
> How about phytagoras ??

> Function Get2DDist(X1, Y1, X2, Y2,) As Currency
>     Get2DDist = Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2 )
> End Function
> if Get2DDist(blabla) < Circle1Radius then BUM!

Thankyou for your response, but I think you misunderstood my post.

It is clearly a simple process to determine if a collision has occured
(ignoring sweeps for now), but a somewhat subtler process to determine what
to do afterward. Collision Response, not detection.

Thankyou anyway



Sun, 26 Dec 2004 07:10:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TIMER and 2d collisions

2. 2D collision detection

3. Collision Detection 2D

4. Response Redirect doesn't Work - No me funciona Response Redirect

5. Collision detection routines between images

6. Collisions in 3D?

7. Sprites and collision detection

8. Collision detection problems w/ scrolling?

9. One Last Help..Collision Detect

10. Collision detection

11. Help with collision algo...

12. Collision detection

 

 
Powered by phpBB® Forum Software