Jump to content

Collision between sprites


malakiah
 Share

Recommended Posts

Hello,

 

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.

Vittorio

example.png

Link to comment
Share on other sites

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

ChCzCN9.jpg

 

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).

https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection#Separating_Axis_Theorem

 

Here's an example of SAT with phaser. 

http://hexus.github.io/phaser-sat-example/

https://github.com/hexus/phaser-sat-example

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.

https://codepen.io/osublake/pen/f0122809730d67335264dcd50f44cad7.js

 

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.

https://codepen.io/osublake/pen/eMvZmo.js

 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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