Some raycast function will be great, for messure distance, and shoot effect (detect impact positions) etc.
Unity3D has good raycast system. Now you must "fire" physics object and wait for collisions and its not good for performance.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Feel free. PRs welcome.
Raycasting is actually built in to MatterJS. :grin: It can be used within Phaser 3.
Would be great for Arcade though, for sure, especially since there's a quad tree available.
Perhaps I could make an example for raycasting with MatterJS, if there isn't one already.
One thing to note about the raycasting in Matter (which I was just looking into) is that it doesn't make use of the broadphase collision filtering, so it's going to be rough if you try to do a few raycasts in one tick against a lot of bodies (e.g. a tilemap).
Yeah, it would be faster to use a broadphase test first to collect all the bodies within the bounds of the ray, then perform the raycast against those bodies.
https://github.com/liabru/matter-js/issues/181#issuecomment-294450986
This should point you in the right direction.
Heh, thanks. Ended up there as well and thought about turning it into a plugin, but my use case was covered by sensors so decided to just stick with them for now.
@mikewesthad out of curiosity, by 'sensors' do you mean you made a tile with an empty appearance and tested for collision against that tile or is there some other abstraction in Phaser that's for this sort of thing?
MatterJS bodies can be made into sensors, which means they don't have any impact with other bodies, but they can still be used to detect collisions. Here's a great example:
http://labs.phaser.io/edit.html?src=src/game%20objectstilemapcollisionmatter%20platformer%20modify%20map.js
@the-simian, exactly what @hexus linked 馃憤. I was actually looking to raycasting initially to clean up a few of those Matter platformer examples that I created. The vanilla Matter example for sensors might also be useful: http://brm.io/matter-js/demo/#sensors.
@hexus you are fantastic, thank you for the link! @mikewesthad , appreciate the followup!
I re-stumbled across this today. I ended up writing something for raycasting, at least to suit my own needs. I still need to abstract it into a plugin but the code is here : https://github.com/simiancraft/create-phaser-app/tree/master/src/plugins/lightrays
I used it to make literal light rays via raycasting, but I know it could be used for like enemy vision and things like that. You can see them here: https://simiancraft.github.io/create-phaser-app/
The scripts do two things
Big idea was to integrate this capability with tiled
On the other hand this is maybe the third time I've done something like this that perhaps Matter does out of the box. On another project I used kind of a messy way for complex polygon overlapping, which it seems matter does out of the box. I had to do something messier, by checking if complex-polygon-A contained certain points in complex-polygon-B
anyways I just posted this in here in case anyone else (like me) was at some point searching about raycasting in phaser and stumbled across this.
Thank you for opening this feature request (all those months ago!). As the development of Phaser 4 has now started I am tidying-up the repo and closing off old issues that won't be directly fixed or implemented in Phaser 3 by me. I would still consider community PRs that address this issue, however, and have left the GitHub tags intact so others can track them if they wish to get involved. However, I'm afraid this is no longer a feature that will be added to v3.
Most helpful comment
Raycasting is actually built in to MatterJS. :grin: It can be used within Phaser 3.
Would be great for Arcade though, for sure, especially since there's a quad tree available.
Perhaps I could make an example for raycasting with MatterJS, if there isn't one already.