# 2D collision handling between two different moving objects

• 03-21-2011, 02:13 PM
Silversurfer20
2D collision handling between two different moving objects
Hi,

I'm making a 2d top-down space strategy game with a variety of space ships in Java. Up till now I've simply had collision detection between ships and weaponry, edges of the screen etc, but now I want to try and go a step up and cause ships to damage and rebound in the appropriate directions when colliding with one another. Actually detecting the collision is not too difficult but I'm struggling with what to do after that.

How can I work out from the ships Velocities, Mass and angle of direction what the effect on them should be?
• 03-22-2011, 05:46 AM
Presumably you already know the velocities of each object, else you can't paint them in the first place.

Collision detection of moving objects (even if 1 is stationary) can be difficult if the velocities are high enough, because as you update positions, it's possible for a fast object to logically pass through another object that point-by-point collision detection will not discover. This can happen because positions are updated in discrete jumps to correspond with the frame rate. To handle that, you're in the realm of solving linear differential equations. For objects moving in straight lines at constant velocity, the collision check is pretty straightforward, but if you don't have a good math background, you're going to need to partner with someone who does, or use a physics engine, or limit velocities such that this scenario is impossible.

At any rate, if two nondeforming point-objects collide, their new velocities are determined based on their respective velocities and masses according to the law of conservation of momentum, which states that m1*v1+m2*v2 = a constant, combined with Newton's 3rd law which states that the the sum of the forces each object experiences in each dimension will be 0. If your eyes haven't glazed over let me know.
• 04-04-2011, 12:57 PM
Silversurfer20
yeah... unfortunately I only understood about half of what you just said. :( I don't think the velocities should be so high that objects can pass through each other without recognising a collision, though I am working on changing the way I look at ship to ship collision detection as currently it waits till a ship has moved and then checks if it has moved into the same position as another ship, but I instead want to check the position it is going to move to BEFORE allowing the move, if that makes sense.

I've also yet to assign masses to any of my ship types as I am still trying to understand everything. Could you perhaps explain a bit more?

Thanks so far
• 04-05-2011, 06:20 AM
Have you had a basic physics class, and do you have a good grasp of trig?
• 04-12-2011, 11:23 AM
Silversurfer20
I can handle the trig ok but I'v never done any physics, which is where I'm falling down
• 04-23-2011, 01:14 PM
I_S_Patil
I can help u.. If u r ready to accept objects as Non-Elastic....
i.e., U should assume that your space ships r not undergoing any deformation in
their shape. If their shapes change.. Then law m1*v1=m2*v2 fails.
Because the momentum of both ships is lost due absorption of energy in changing the shape of space ship.
• 04-23-2011, 09:15 PM
Silversurfer20
hmm well I'm fairly certain I want it to be non-elastic. The idea is that the ships will take some damage based on speed and weight, e.g. if a small ship goes flying into a larger one, the small ship might ricochet a lot and taken a lot of damage while the larger one is affected a lot less.
• 04-24-2011, 06:00 AM
I_S_Patil
I hope u still have idea of having Elastic collision...
It will be difficult to analyse it precisely.. So u can adopt following method

1. Assume elastic collision
2. Find the final change in direction & velocity of space ships
3. Since u want to assume damage to space ship, reduce the final velocity of
both ships by some % ( Say 3-5 % ).
* Do not change the direction of ships

Still if u do not know to calculate change in velocity & direction of ships after collision as Non-Elastic,i well tell u how to do that
• 04-25-2011, 06:41 PM
Silversurfer20
I'm happy to still do elastic collision and just estimate some damage afterwards, but its working out the change in velocity and direction that I need the help with.
• 05-17-2011, 02:04 PM
I_S_Patil
Scanned copies of problem
Sorry for taking such a long time..
Though i completed these very early..
I could not upload these because i was busy in my work.
• 04-05-2012, 10:32 AM
I_S_Patil
Re: 2D collision handling between two different moving objects
I see lot of views for this thread. Has any body observed my calculations. Give feed back.