Jump to content

Circle collision


STuFF
 Share

Recommended Posts

Hello,

 

I'm trying to do something easy, and I did it very quickly with Phaser, that framework is really awesome ;)

 

I made a big ball (a sprite) bouncing in the game world, then I added some "platforms" in the middle of the world (some sprites too) then everything was ok. The ball bounced on the edges and on the platforms.

 

BUT. My ball is a circle (obviously) and my platforms are rectangle, so, in some case, the collision is not accurate, see example below :

 

xm8q9w4u.png

I'm using this.game.physics.collide(); to test collision. I tried to use the processCallback to test the collision precisely using Phaser.Circle.intersectsRectangle() which is very easy to achieve, but the "bounce" already occured at this time. I don't know what to do next, I don't know if I'm on the right way.

 

Of course, I don't want to use an overkill physic system like box2D or whatever else...

 

Can someone could help ?

 

thanks

Link to comment
Share on other sites

The way you'd do it would be to use body.customSeparateY on the circle and then in your processHandler you can check the circle / rectangle intersection. However the problem is that with a large circle/rect (as in the image above) the circle body will only pass the 'collide' test for the first few iterations, depending on speed, after which it just becomes 'embedded' and the two rectangles are no longer considered to be 'colliding' but are instead overlapping. Of course the problem is that you want it to carry on thinking it's colliding right up until the Circle itself does actually intersect, but that's just not how it works at the moment :-/

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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