AboulEinein Posted June 1, 2017 Share Posted June 1, 2017 I have a sprite of a character moving and I'm trying to apply physics collide on it that when it hits a rock for example health is decreased. I managed to achieve collision but as rectangular shape of the image, what I want to achieve is the collision happens on the boundaries of the character itself. I used PhysicsEditor to generate the JSON file, but I'm still not sure how to use it to achieve pixel perfect collision. Any thoughts? Link to comment Share on other sites More sharing options...
Big Southerly Games Posted June 1, 2017 Share Posted June 1, 2017 First up you need to apply the P2 physics engine to the body. Then apply the shape you made with the Physics editor to the body. In one of my games I do something similar with player grenades so they can roll and bounce around in a believable manner. The code snippet looks like:Loading the shape file exported from Physics Editor this.game.load.physics("objectPhysics", "img/weapons/objects_physics.json"); Applying the shape to the sprite myGame.phaser.physics.p2.enable(playerGrenade, false); // Add our PhysicsEditor bounding shape playerGrenade.body.clearShapes(); playerGrenade.body.loadPolygon("objectPhysics", "Grenade", playerGrenade); Link to comment Share on other sites More sharing options...
AboulEinein Posted June 2, 2017 Author Share Posted June 2, 2017 I did that, but my problem is that my sprite has animation so each frame has a different polygon thus collision detection should apply to the current frame in the animation. What I did is that I loaded all the polygons to the sprite body then with each frame change I disable and enable the polygons that correspond to that frame. But this is a very tedious and extensive solution, and I'm wondering if there's a better solution or if I'm missing something Link to comment Share on other sites More sharing options...
harishkumarvijay Posted October 2, 2018 Share Posted October 2, 2018 Hi, I am facing the same issue. Have you found any solution for changing the polygon shapes with respect to their animation frames? It would be really helpful if you could share your thoughts. Link to comment Share on other sites More sharing options...
Recommended Posts