Search code examples
paperjs

Collision detection in paper.js


I'm implementing a simple game in Paper.js for educational purposes. The game features some bacteria, whose bodies are Path.RoundedRectangles. I'm trying to write a function colliding(roundedRect1, roundedRect2) using Paper's PathItem.intersects(item) method, but it returns true every time!

Before I scrap this tactic and write my own collision detection, I'm wondering if anybody has successfully used Paper's builtin intersects for this. Thanks!


Solution

  • You use the code path.intersects(otherPath) which returns true or false.

    You can take a look at a simple example that shows intersect works here:

    Simple Paper Sketch showing intersect function.