harishkumarvijay Posted October 2, 2018 Share Posted October 2, 2018 I'm trying to apply physics to a animated sprite. I used PhysicsEditor to generate the JSON and loaded the polygon shape for the first frame. Collision detection is not happening when i try to clear the shapes and load the polygon dynamically with respect to animation. Is there any method to clear and load the polygon dynamically to detect collision. Any thoughts ? Link to comment Share on other sites More sharing options...
harishkumarvijay Posted October 3, 2018 Author Share Posted October 3, 2018 HI I found a solution for the issue. Every time when I clear a shape from p2 physics body, it looses its collision group settings. So whenever we clear and load new shape we need to set the collision group again. This solved my issue. Code Snippet: // Collision Group var collisionGroup = game.physics.p2.createCollisionGroup(); // Removing the previously loaded or default shape sprite.body.clearShapes() // Loading a new shape with respect to the sprite sprite.body.loadPolygon(JSONData, name); // Setting the collision group to the body sprite.body.setCollisionGroup(collisionGroup) Link to comment Share on other sites More sharing options...
Recommended Posts