nicofisch5 Posted August 20, 2014 Share Posted August 20, 2014 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 More sharing options...
ZoomBox Posted August 21, 2014 Share Posted August 21, 2014 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 More sharing options...
valueerror Posted August 21, 2014 Share Posted August 21, 2014 if you are using p2 use a constraint for this.. for example a revolute constraint.. you can the remove the constraint whenever you dont need it anymore.. Link to comment Share on other sites More sharing options...
ZoomBox Posted August 21, 2014 Share Posted August 21, 2014 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 More sharing options...
nicofisch5 Posted August 21, 2014 Author Share Posted August 21, 2014 Thanks for your answers. @valueerror can you give an example ? Link to comment Share on other sites More sharing options...
Dumtard Posted August 21, 2014 Share Posted August 21, 2014 http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=lock+constraint.js&t=lock%20constraint Link to comment Share on other sites More sharing options...
Recommended Posts