I'm currently working on a side scrolling game project using Phaser 3 and the Arcade Physics Engine. However, I've encountered a challenge regarding collision detection with polygon shapes. I'd like to incorporate polygon collision support into my game without having to switch to another physics engine like Matter.js. Is there a way to achieve this within the confines of the Arcade Physics Engine?
I understand that the Arcade Physics Engine primarily supports basic shapes like rectangles and circles for collision detection. However, my game requires more complex polygon shapes for collisions.
I've explored various resources and documentation but haven't found a straightforward solution. Can anyone provide guidance or share insights on how to implement polygon collision detection while still utilizing the Arcade Physics Engine? Any tips, code snippets, or recommended practices would be greatly appreciated.
To reiterate, the goal is to integrate polygon collision detection seamlessly into a Phaser 3 game that relies on the Arcade Physics Engine, avoiding the need for a complete overhaul or migration to a different physics engine.
The first thing that comes to mind is to use the
processCallbackfunction of thecollideor theoverlapfunction. (link to the documentation)In this callback function you could calculate if an object has collided with an other object, if so return
trueand than thecollideCallbackis called, if not returnfalseand no collision has occured.With other words you would have to do all the heavy lifting of checking for collision between the objects, polygons or ..., that are passed to the
processCallbackfunction.Apart from this I don't know easy way out-of-the-box to achieve this with arcade physics, but I'm by all means no expert.
Btw.: you could check if there are some plugins, that add this functionality (you could checkout https://phaserplugins.com/, https://rexrainbow.github.io/phaser3-rex-notes/docs/site/plugin-list/ , but you have to be careful some plugins out there are for phaser 2/CE )
Here a very basic example, how this could work:
(I'm not sure, if this is the most efficient way to do it, but it only a demo)