Jump to content

Problems on collision


bandrei2408
 Share

Recommended Posts

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 :

 

QrRev3i.png

 

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...