Jump to content

Detect circle collision inside shape


Juan
 Share

Recommended Posts

Hello,

This is what I'm trying to do:

I have a draggable circle inside a shape which collides with its edges (the shape's edges).

Any idea of how I can achieve  this?

lZFXg3l.png

I tried using P2 physics with both sprites, but I couldn't make the circle stay and collide inside the shape.

Link to comment
Share on other sites

13 minutes ago, jjwallace said:

is this for a user interface?  I only use my own physics so :( 

I am not sure if P2 has that function, perhaps there is a way.

This is for a game.

And yeah. Whenever I load it the circle goes out the shape.

Link to comment
Share on other sites

If you know your polygon shape data and you are working with simple shapes (like the example provided), you could try  something like this :

 Another idea: If you have your geometry data , you could try addLine and create connecting lines...  Still not very convenient however...

Link to comment
Share on other sites

On 1/8/2017 at 6:17 PM, samid737 said:

If you know your polygon shape data and you are working with simple shapes (like the example provided), you could try  something like this :

 Another idea: If you have your geometry data , you could try addLine and create connecting lines...  Still not very convenient however...

It works, but the thing is that I'll be using complex shapes, I used this one so you could get my idea. 

Link to comment
Share on other sites

 Here is an example of how to generate the shape by hand so to say:

The idea is to build the shape from your data points (they must be ordered as a path) so that it will act as a closed surface (its is not entirely connected, but its super close). You could use this if your shape is not too complex ( disconnected, then it will definitely fail). In the example the shape is interpolated, but you dont have to do this...

I think you can also build your polygons using other software, but I have not used them yet....If you make random shapes in your game, then the example would be pretty useful. Also, you can see that you have to consider performance carefully (many p2 bodies).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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