Correctly misusing Box2d to get time of impact
Posted: Sat Mar 05, 2016 2:33 am
Given two physics objects that collide, how can I determine at what point in the frame they actually collided?
For instance, two polygon shapes are headed at each other such that, during the 1/60 second timestep, they collide. How can I use the callbacks and the various position/velocity getters before and after the world:update to determine the exact time of collision? For instance, if they hit at 0.01 seconds.
The reason I'm trying this is because I am working on a game that involves multi kilometer long entities traveling double digit kilometers per second billions of meters from the origin. I have written code that can coarsely determine if they're likely to collide using bounding-sphere-based continuous collision detection, but I'd like to use Box2d to compute if the bound polygons actually collide and what their rough change in velocity will be as a result of the collision.
So I'm creating and destroying bodies for a single frame to try and determine if they actually collide. There will only ever be 2 objects in the world at any time. After I compute the results of all of these collisions, I want to sort them by time of impact so that I can call the object callbacks in the correct order.
Like I said, misusing. But I understand what the consequences are and I find them to be acceptable. Most important is detecting the actual collision, which I am confident that box2d will provide with great precision. I just want a rough idea of the results of the physics (and I don't care about stacking stability).
For instance, two polygon shapes are headed at each other such that, during the 1/60 second timestep, they collide. How can I use the callbacks and the various position/velocity getters before and after the world:update to determine the exact time of collision? For instance, if they hit at 0.01 seconds.
The reason I'm trying this is because I am working on a game that involves multi kilometer long entities traveling double digit kilometers per second billions of meters from the origin. I have written code that can coarsely determine if they're likely to collide using bounding-sphere-based continuous collision detection, but I'd like to use Box2d to compute if the bound polygons actually collide and what their rough change in velocity will be as a result of the collision.
So I'm creating and destroying bodies for a single frame to try and determine if they actually collide. There will only ever be 2 objects in the world at any time. After I compute the results of all of these collisions, I want to sort them by time of impact so that I can call the object callbacks in the correct order.
Like I said, misusing. But I understand what the consequences are and I find them to be acceptable. Most important is detecting the actual collision, which I am confident that box2d will provide with great precision. I just want a rough idea of the results of the physics (and I don't care about stacking stability).