indigo icon indicating copy to clipboard operation
indigo copied to clipboard

Physics: Solve the 'tunnelling' / 'bullet through paper' problem

Open davesmith00000 opened this issue 1 year ago • 1 comments

This is the problem where an object is moving so quickly that it's next move iteration jumps it to the other side of an object that it ought to have collided with.

davesmith00000 avatar Jul 16 '23 19:07 davesmith00000

Notes to self:

On the physics-noodling branch, the engine is now fast enough to show that the tunnelling problem will always exist with the current implementation (seems obvious in hindsight) because fundamentally, we have to assume 60fps as an upper iteration bound, and if the object is moving sufficiently quickly, it will eventually skip over something.

So what to do?

Currently the engine is a sort of crude 'discrete' engine, in that it really just compares complete moves per iteration. That works perfectly ok (or ok enough) for anything doing a "safe" move, by which I'm meaning (possibly wrongly) that the next position is overlapping the previous position because it's moving slowly enough. In that scenario, the likelihood of tunnelling seems acceptably small (and so edge cases seem ignore-able, at least for now), and so I can treat these as the happy path and just use the existing approach for the calculations.

For "unsafe" items, what I need to do, is do "some" iterations from the old to new positions - ideally leaving no gaps but maybe there's an upper bound to attempts? - and estimate a TOI (time of impact) when it hits each thing (including other unsafe items, so that means iterating them together...), and then solve the collision(s) with the earliest TOI(s), and skip anything else. For example, if at the end of it's move (TOI: 1), a ball hits another ball, but half way there it would have hit a wall (TOI: 0.5), then the ball to ball collision never happened, and we just need to do the ball to wall collision.

davesmith00000 avatar Dec 30 '23 22:12 davesmith00000