Public Group

# Collision Detection Response

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

## 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 on other sites
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 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 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 on other sites
Quote:
 Original post by TemmywizThanks 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 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 on other sites
Quote:
 Original post by SquirmIn 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) * finalVelsofinalVel = (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 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 on other sites
Wow! Thanks Squirm!!! I got it.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013228
×