bandrei2408 Posted February 14, 2014 Share Posted February 14, 2014 Hello,I've just started to learn Phaser engine and i encountered a bug while i was developing a game.I created a sprite and attached to his body a polygon as you can see in the image. I also attached to players body , in create function, a rectangle just so i can make his body smaller. However the player and the sprite collide really really strange, as you can see in this image : Have i done something wrong ? I attached the full code below in case you need it. I don't think it's a problem of coding to be honest, since i checked it alot of times before posting my question here.Thanks for your time !code.txt Link to comment Share on other sites More sharing options...
bandrei2408 Posted February 15, 2014 Author Share Posted February 15, 2014 FIgured it out by reading SAT.js that you need those polygons to be convex in order for the algorithm to work. However any idea if i need to apply collision on 2 concave polygons ? Link to comment Share on other sites More sharing options...
bandrei2408 Posted February 15, 2014 Author Share Posted February 15, 2014 Figured it out again ! I split the concave polygon in 2 convex polygons and ran the SAT Algorithm. It's working perfectly now ! Solution : var obstacle = obstacles.create(pointX,pointY,'obstacle_bot');var polygon_top = new P(new V(pointX,pointY), [new V(0,0), new V(31, 69), new V(43, 69), new V(72, 0)]);obstacle.body.polygon_top = polygon_top;var polygon_bot = new P(new V(pointX,pointY), [new V(0,0), new V(0, 233), new V(12, 233), new V(12, 0)]); obstacle.body.polygon_bot = polygon_bot;var P = SAT.Polygon;var V = SAT.Vector;Then i ran the SAT Algorithm to check collision between obstacle.body.polygon_bot and player.body.polygon / obstacle.body.polygon_top and player.body.polygon .If you have a more efficient algorithm for this please share it ! Link to comment Share on other sites More sharing options...
Recommended Posts