Jump to content
  • Advertisement
Sign in to follow this  
Temmywiz

Collision Detection Response

This topic is 4796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After detecting collision between two circles by using distance between their centres and radii, how do I make them stick together and move off together after collision? Ok, it's like this. I have two circles - one big and one small. I want the small one to stay on top of the big one and move off together with it after their collision. How do I do that? Do I have to draw frames of the two balls together or something?

Share this post


Link to post
Share on other sites
Advertisement
Depending on how your movement works, I suggest either the small circle takes over the motion of the big circle, or it just takes the big circle as parent object.

When updating, it takes the position of the parent object, and calculates it's new position relative to it. You might want to take radius into account aswell.

Toolmaker

Share this post


Link to post
Share on other sites
You used the word 'draw' in a question about physics, which is a bad sign. Do the physics. Draw the world. Do neither at the same time or in the same place.

For the actual question though, do you actually want them to stick, or just collide completely non-elastically? In other words, if a third ball hits them after the collision, do all three stick, or could it break them apart?

[edit: mmm, you say "on top" - do you mean on top as in physically (you sound to be using 2D circles) or do you mean graphically (one drawn over the other)?]

[Edited by - Squirm on June 1, 2005 5:05:19 AM]

Share this post


Link to post
Share on other sites
Thanks Toolmaker & Squirm.
About your question, Squirm, I want a third circle to break the 1st and 2nd circles apart. (I am talking 2D circles, not spheres). I just want the two circles to appear to move off together (either physically or graphically, dunno).

Share this post


Link to post
Share on other sites
Quote:
Original post by Temmywiz
Thanks Toolmaker & Squirm.
About your question, Squirm, I want a third circle to break the 1st and 2nd circles apart. (I am talking 2D circles, not spheres). I just want the two circles to appear to move off together (either physically or graphically, dunno).


I would hope you meant physically and graphically. Basicaly, assuming you detect correctly the collision, you just need to see what position one is in compared to the other, then when the second moves, adjust the first accordingly. Say the small circle follows the big circle. You detect a hit. You check the positions to see that the big circle is at (0,0) and the small at(1,1), so next few frames, when the big circle moves, say to (1,3), you put the small at (2,4), which will be the same relative to the big circle, just like when they first hit. Do this each frame that the big circle moves and the small circle will follow with ease.

Share this post


Link to post
Share on other sites
In that case they don't 'stick' they just have the same velocity...

Conservation of momentum states that the sum of mass * velocity before and after the collision is constant. Since after the collision, both have the same velocity, that gives us:

smallMass * smallVel + largeMass * largeVel = (smallMass + largeMass) * finalVel
so
finalVel = (smallMass * smallVel + largeMass * largeVel) / (smallMass + largeMass)

So all you have to do, having detected that they collide, is run the above calculation, and set the velocity of both circles to finalVel.

Each thing above ending in Vel is a vector, which means it contains both an X component and a Y component. I am assuming you understand, but if you don't, ask and I shall go over it quickly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Squirm
In that case they don't 'stick' they just have the same velocity...

Conservation of momentum states that the sum of mass * velocity before and after the collision is constant. Since after the collision, both have the same velocity, that gives us:

smallMass * smallVel + largeMass * largeVel = (smallMass + largeMass) * finalVel
so
finalVel = (smallMass * smallVel + largeMass * largeVel) / (smallMass + largeMass)

So all you have to do, having detected that they collide, is run the above calculation, and set the velocity of both circles to finalVel.

Each thing above ending in Vel is a vector, which means it contains both an X component and a Y component. I am assuming you understand, but if you don't, ask and I shall go over it quickly.


Please go over it quickly. Thanks!

Share this post


Link to post
Share on other sites
ok...

a circle 'thing' is at x,y and has velocity vx,vy

These pairs of X and Y occur alot, and are usually treated as single values, so we have the concept of a vector, which contains an x and a y, and we have a position and a velocity, each of which are vectors, and finally we have a circle, which has a position, a velocity, and a radius.

to say that Velocity C = Velocity A + Velocity B really means:
C.x = A.x + B.x
C.y = A.y + B.y

And when I multiply a vector by a scalar (a single number), such as velocity * mass, I mean this:

Velocity V * Mass M = Momentum (V.x * M, V.y * M)
Mass is a scalar, Velocity and Momentum are vectors...

I hope that makes sense. For more details, search within gamedev or within the flipcode site for vectors and matrices. There are ways to simplify life a lot when doing this, including several ready made vector classes so that you really can write Velocity = Velocity * 2 in your code and it handles all the X and Y stuff for you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!