Matter physics raycasting

I’ve looked all over but cannot find a way to raycast while using the Matter.js part of Phaser. Is it even possible? If not, is there a good alternative?

Is there a way to detect if a matter body is in front of the player without the player having to run into it?

You can, it is somewhat hidden though!

Phaser.Physics.Matter.Matter.Query.ray(ArrayOfMatterBodies, fromPoint, toPoint, rayWidth);

This will return an array of bodies hit by the ray, index 0 being the first body. It has to be matter bodies (I think), you find them in scene.matter.world.localWorld.bodies. This checks against all bodies, so might have to do some processing to get only the bodies you actually have to check against.

Docs about it here: https://brm.io/matter-js/docs/classes/Query.html

Possibly there is an easier way to do the ray, but this is what I used.

Awesome! I saw the matter.js website but wasn’t sure the whole framework was incorporated into Phaser.

Thanks! Just a quick question, do you know of a way to display the line for debugging purposes?

Nvm. I can just draw the line using the two points…lol. Thanks again.