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
between 5 and 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

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

impulse

Sun, 26 Dec 2004 03:26:11 GMT
2D Collision Response

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

> 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

> impulse

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

Quote:

> 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

 Page 1 of 1 [ 3 post ]

Relevant Pages