TL;DR: How do I detect collisions between meter-sized objects moving tens of kilometers per second in arbitrary directions? =S
Let´s say we theoretically have a 20x5 meter sized (2D) space ship in orbit around the Earth. It´s currently flying at around 7 km/sec relative to the Earth in a clockwise orbit. However, Earth is a mean bastard and launches a 4x1 meter sized missile to take out our poor little space ship. The missile enters an unstable orbit COUNTER clockwise around the Earth and attempts to intercept the ship. Its very fast and reaches a speed of around 13 km/sec while accelerating. With the relative speed between the ship and the missile is between 15 and 20 km/sec depending on the angle the missile is coming from, and I want it to be possible to for this collision to happen.
However, it get´s worse. The simulation is sped up so that one day in real life is one year in simulation time. The simulation is however run at 30 updates per second, which gives us a time step of 365/30 = around 12 in-game seconds per update. This is low enough to simulate accurate stable orbits, but obviously not for doing traditional collision detection by detecting intersections between geometry since the ship and the missile will move over 20km relative to each other in one update. Doing many smaller updates, even for just a subset of all bodies, is not practical due to the several thousands of steps needed to detect.
Detecting collisions would be done in multiple stages. The first stage could be a quad tree to filter out most bodies. We could then do a bounding box collision test between AABBs of the movement lines. Then we could do a line intersection test between the two movement lines, and finally more sensitive tests to determine exactly exactly where the missile hit the ship, so we can calculate a collision response. However, this is can pose BIG problems. What if the collision causes the ship to completely change course and should have hit another nearby body? Since we still complete a full time step before applying new forces the body will end up several kilometers away from it´s correct position.
To solve this I´m going to rely on assumptions. For example, when the speed difference is big enough we can safely assume things based on the properties of the bodies. In the above case we can easily predict that any detectable collision between the missile and the ship will detonate the missile, disintegrating both the ship and the missile due to collision forces, the missiles´s payload and the ship´s weapons/reactor exploding. As long as the collision is detected, collision response is very easy.
Another case would be if a a rail gun or gauss cannon launched a small projectile at an insanely high speed (30+ km/sec) towards the ship. Again, assumptions can easily be made. The bullet will most likely pass straight through the ship with a very low loss of velocity (though with potentially fatal damage to the ship), or be absorbed by the shields of the ship the ship is equipped with shields, in which case the kinetic energy of the bullet is pretty low compared to the mass of the ship, so it will be very hard to find a case where this leads to a missed collision. In short, we rely on the fact that a collision either generates a low enough force that it doesn´t matter much or that the generated force destroys the body. It´s in space, and spaceships aren´t really known for being strong or being able to handle X km/sec collisions well. xD
One problem with this idea though is that “destroyed” does not implied “disappeared”. The ship might break up into parts of debris which could tunnel through other bodies if the collision occurs just in front of them. For example: We have 1 ship going in clockwise orbit and a small probe followed by a 5 km long battle cruiser going counter clockwise. The simulation accurately detects a collision between the probe and the ship, and both heavily break appart and continue in their current directions. The debris from the ship would possible spawn behind the battle cruiser since the battle cruiser very likely has passed the point where the probe and the ship collided by the next time step. Creating the debris in-between the time steps (= create an extra time step) would force us to rewind the whole simulation to the time of the collision which will perform terribly, be very difficult to implement and possible cause pathological scenarios when a collision requires undoing collisions that were detected earlier, e.t.c.
Uh, this kind of ended up with me just brain storming my ideas here. The TL;DR question still stands though, how would you do this?
And here´s a question to the physics pro´s out there: Kinetic energy depends on velocity square, but velocity has always been relative to a fixed point in the system. For example, a rocket taking off from Earth. In this case the rocket starts at 0 m/s and accelerates upwards. The faster it goes the more energy is needed to accelerate it more. However what happens if we use a velocity relative to the sun? The Earth is blasting through space at an insane speed compared to the speed of the rocket. That would mean that the rocket isn´t accelerating from 0 to 11 km/sec to get into orbit, but maybe 100 to 111 km/sec, or even “accelerating” from 100 to 89 km/sec depending on where on Earth the rocket is launched. Guys, did I break physics?