titmael Posted June 19, 2014 Share Posted June 19, 2014 Hi, I have multiple sprites for my player to animate him. Let's say he has an axe sometimes. Is there any way to compose those sprites with custom shapes and detect collisions with those shapes ? I use PhysicsEditor for custom shapes and export in JSON format. I know how to load those custom shapes. I mean, the player's body has a shape to collide against world or enemies and his axe has a shape to collide with enemy in order to hit them. Is it possible ? In my game I use this to check some collisions :this.game.physics.p2.setPostBroadphaseCallback(this.checkCollision, this);So in my function checkCollision(body1, body2), can I know which shape of each body collided ? Not sure if I'm clear, I'm not alone in my head Link to comment Share on other sites More sharing options...
titmael Posted June 19, 2014 Author Share Posted June 19, 2014 Looks like I found a way to do it, here is a dumb json I used to test :{ "bone": [ { "isSensor": false, "filter": { "group": 0, "categoryBits": 1, "maskBits": 65535 }, "polygons":[ [ 0, 24 , 1, 1 , 9, 1 ] ] } , { "isSensor": false, "filter": { "group": 1, "categoryBits": 1, "maskBits": 65535 }, "circle": { "radius": 10.000, "position": [ 9.667, 13.000 ] } } ] }In PhysicsEditor I created 2 shapes on the same sprite, changed the group (0 and 1). And using this to detect collision :this.body.onBeginContact.add(function(bodyA, bodyB, shapeA, shapeB, contactEquations)I can check shapeA and shapeB to know the group so to know which shape collided. I'm a right ? Is there any better way to do it ? Link to comment Share on other sites More sharing options...
Recommended Posts