Jump to content

Better Collision Detection


peterje
 Share

Recommended Posts

Currently, the Sprites in my game only have rectangular collision detection, but more complex shapes for their hitArea. This makes drag & drop very nice but I am wondering if the same is possible for collision detection. Somehow, Scratch has this ability. As shown here, even for shapes where a hull would not be very good, the collision detection is still perfect. Anyone have an idea if this can be done in PIXI? Or am I just limited to rectangular collision detection?

 

For example, a sample sprite I have looks like this:

image.png.7eda77484fccc951639619b82a8610b9.png

 

And the hitArea I generated looks like this:

image.png.caa25823e23e429fd8741e5be45e25d7.png

 

The hit area is represented as an array of polygons:

image.png.ddac6a85101a9d0641adc487be4de1fa.png

 

Assuming each of my sprites also has a hitArea of N polygons, is there a library I can use to detect collision between the two?  I looked at the Separate Axis Theorem, but that seems to only work when each sprite can be represented as a single polygon. However, mine are represented as many polygons together.

 

Any suggestions? 

Link to comment
Share on other sites

PixiJS does not have physics. At all. the only physics it does have is contains() for different shapes.

Take p2 https://github.com/schteppe/p2.js , build from source (not from npm!!!!, just use "grunt" to do that), make pixi stage and physics world separated, store pixi/p2 components in your own entity class. The usual ECS-y architecture.

Here is how its done: https://codesandbox.io/s/smoosh-river-fie1l

Edited by ivan.popelyshev
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...