hexus / phaser-arcade-slopes

:triangular_ruler: A Phaser CE plugin that brings sloped tile collision handling to the Arcade Physics engine
MIT License
126 stars 16 forks source link

Prevent internal edge collisions without heuristics #40

Closed hexus closed 7 years ago

hexus commented 7 years ago

The heuristics are pretty painful now, when it comes to maintainability and reliability. It's time to use SAT.js more wisely.

This is part of the 0.3.0 roadmap, and the item looks like this:

http://www.wildbunny.co.uk/blog/2012/10/31/2d-polygonal-collision-detection-and-internal-edges/comment-page-1/#comment-1978

The discussion here proposes ignoring collisions that occur with internal edges, which is a nice solution, and in fact what the heuristics do already.

After some experimentation in the ignormals branch (hah) at the same time as tinkering with SAT.js, this turns out to work exactly the same way, except it resurfaces the issue with skipped collisions for small and fast projects between tile seams (#38).

The direction I want to take this is using SAT.js to first determine if there is any collision, and instead of using the shortest separation that it gives back, use the shortest separation that isn't an ignored axis, which are indeed now flagged as part of each tile's polygon edge normals.

I tried to do this by just skipping flagged normals in SAT.js to let it fall back to the smallest non-ignored normal, but the results were identical, which means either:

This can probably be achieved outside of SAT.js with a custom testPolygonPolygon() function.

hexus commented 7 years ago

Need ghost vertices:

http://www.iforce2d.net/b2dtut/ghost-vertices

hexus commented 7 years ago

Okay, so technically this is heuristics, but they're generalised for the cases of these tiles and the edges of their neighbours.

They're also evaluated at build time, not at run time as part of the game loop. This essentially improves run time performance, provided that filtering down responses isn't making it tonnes worse.

hexus commented 7 years ago

Yaaas, this is looking great! Red lines are the extra "normals" to ignore; the ignormals. :full_moon_with_face:

image

Now for some further optimisation. Perhaps this should be left to #42 though, so we're probably done here.

hexus commented 7 years ago

This can be considered done. And it's fast as heck. 😎