3
votes

I am working on a 2D game which includes high-speed projectiles that will impact high-speed (and potentially very quickly rotating) polygonal target objects. I have been experimenting and searching for a robust collision detection algorithm that will work for me.

If fast rotation was not a factor (i.e. 0 or slow rotation), then I can just use ray casting, which I have had general success with in the past and even with this project. However, there are a few edge cases involving fast rotation where this system can break down. For instance, check the following image:

The projectile (black circle) is moving straight down very fast. The target (red rectangle) is rotating approximately 180°/frame. The projectile should contact the target some time between the 0th and 1st frame, but instead will completely miss.

In the above example, the projectile (black circle) is moving straight down very fast, and the target (red rectangle) is rotating approximately 180°/frame. The projectile should contact the target some time between the 0th and 1st frame, but instead will completely miss.

Most of the time this would be remedied using small discreet time steps between each frame, but due to the high speed that objects will be moving, this will create its own collision detection issues. Not to mention the computational cost. I have also experimented with a convoluted nonlinear ray-casting solution, where I (1) get the velocity vector of the projectile relative to the target, and create functions for the x and y position vs. time, (2) convert x(t) and y(t) to polar to get r(t) and θ(t), (3) add the target's rotation speed to θ(t), (4) convert back to Cartesian. This of course results in a nonlinear "ray" representing the projectile's movement within the frame. Using this "ray" to find a collision point with the target results in a system of equations that is usually analytically unsolvable, and too expensive to numerically solve. Alternatively, instead of (4), I could convert the parametric equation for of the target's line segments to polar, and then again try to solve the system of equations, but in polar this time. This system seems to be just as much of a mess, and is equally unfeasible.

Does anyone have any experience with anything like this, or any suggestions for algorithms to solve this problem? Thanks in advance!

2
You should look for continuous collision detection algorithms, like the GJK collision detection algorithm.EvilTak

2 Answers

0
votes

I dont have specific experience for your problem, but you can make your specific physics calculations to solve it.

According to the question, que projectile actually does not collide at the FPS frequency, so what I would try is calculate the timestamps that the target is interphering with the proyectile's trayectory.

With the rotational speed and the speed of the target and geometry you can calculate when the target is interphering in the proyectile's trayectory (a stright line presumably). This will be a set of timestamps as there are times where there is trayectory interpherence, and where not.

Same for the proyectile, with the speed and acceleration maybe, you can have the timestamp where the trayectories interphere. The straigth proyectile's line, with the space traveled by the rotating target.

Then you can check both timestamps, if there is timestamp overlap, means that there is a collision.

Then another problem is to handle that collision, but for the moment I think that with time calculations with elemental physics you can detect the collisison, that is what you ask for.

It is quite a dense problem to provide an answer, but the approach seems feasable to me.

Hope I made myself unsderstood.

0
votes

There really isn't any magical solution or trick, you will have to reduce the time delta to be even smaller than the period of the rotation frequency and also take into account how far the contact point you expect to be from the center of rotation. The best approach would be to use a fast algorithm for coarse collision detection as both objects get closer (GJK is a good option as it gives the minimum distance between both objects) and use the distance to estimate a new time delta for next calculation.