Jump to content

P2 sprite which capture another one


nicofisch5
 Share

Recommended Posts

Hi,

 

I use P2 physics.

What is the best way to make a sprite catching another when collide ?

In other words how can I "cancel" the collision movement between 2 sprites ?

 

After that, the 2 sprites are "walking" together till a key is down.

 

Thanks in advance.

nicofisch5

Link to comment
Share on other sites

One idea:

-Store both body coordinates

-Destroy both bodies

-firstSprite.addChild(secondSprite); // so they are stuck together forever

-merge both stored body coordinates in one single array

-firstSprite.body.addPolygon(arrayOfCoord);

 

Second idea (maybe easier, but similar):

-Store secondSprite body coordinates

-Destroy secondSprite body

-firstSprite.addChild(secondSprite); // so they are stuck together forever

-firstSprite.body.addPolygon(secondSpriteArrayOfCoord);

Link to comment
Share on other sites

This sounds like the best idea.

But are constraint absolutly not flexible ?

I mean, with my solution, I'm sure the body are stuck together and will keep exactly the same distance in every cases.

 

(PS: i'm just curious, not trying to "get the like" haha)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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