Search code examples
javascriptphysicsmatter.js

How to tell if two bodies are touching with matter.js


I'm using matter.js as a physics engine, and I see that I can detect collisions.

However, I cannot figure out how to tell if two bodies are in contact with one another after a collision occurs. Is there any way to do this?

(In my particular case, I want a ball to jump only if it's touching a particular piece of ground.)


Solution

  • This is a very late answer and I know you already accepted an answer, but I just found this really easy solution. Matter.js has a module called SAT which detects collisions with Separating Axis Theorem. It's single method can be used to detect if two objects are colliding:

    Matter.SAT.collides(playerObject, groundObject).collided // returns either true or false depending on if the two objects are colliding