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

Fixed overzealous ignorance of collision normals for less common tile configurations #56

Closed hexus closed 2 years ago

hexus commented 2 years ago

The heuristic algorithm in TileSlopeFactory.flagIgnormals() was a little too sweeping in its judgements, causing issues like those presented in #55, which demonstrates some more intricate and admittedly untested tile configurations.

This change refines the assumptions made by that method, particularly by comparing neighbouring tile slope angles for a match, and whether slope lines of neighbouring tiles meet properly (whether the end of the current tile's slope line matches the end of its neighbour's slope line).

It also fixes up the slope line definitions for a few tile types where they were inaccurate, as well as adding debug rendering for them.

The change also updates the license's end year from 2018 to 2021.

hexus commented 2 years ago

This change knowingly leaves issues at junctions where slope angles change:

image

Bodies can get caught at these junctions at slow velocities or at very unfortunate angles.

Fixing this would involve comparing the change in slope between neighbours is within a particular threshold, rather than just checking whether they're the same (which is what this fix does).

The true solution for this problem as a whole is handled properly by hexus/phaser-slopes in Matter.js for Phaser 3, which ported Box2D's algorithm that solves this problem for arbitrary neighbouring polygons using ghost vertices.

It could be ported to this plugin with a fair bit of work, but Phaser 2 isn't where I want to spend time supporting things. PRs would be welcome for a change like this.