Jump to content

Collision between sprites


Recommended Posts



I'm developing my first application with pixi.js 4 and I have a problem with collision between sprites.
In my case I use textures with irregular shapes and logically I'm able to intercept collision between rectangular sprites (using Bump library).
I need instead to check collision between irregular shapes as attached example. Is there a way to create an impostor shape attached to sprite in order to have this result?
Thanks for now and sorry for my bad english.



Link to comment
Share on other sites

You can use polygons for your hit areas. It doesn't have to be pixel perfect.



Now google how to do polygon collision detection. There are a lot of resources for this. For convex polygons you can use the Separating Axis Theorem (SAT).



Here's an example of SAT with phaser. 



Link to comment
Share on other sites

You have to install it with npm, but here's a version of it. It only works with convex polygons.



Another way to do this is to check for edge intersections between polygons. That will work with concave polygons. 


Here's the compiled code for that demo.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...