Jump to content

Oriented bounding box (OBB) collision detection for phaser


tmuecksch
 Share

Recommended Posts

Hey there,

 

I wonder if there is any physics engine for Phaser 2.3.0 that works like the arcade physics but enhances it by OBB (oriented bounding box) collision detection?

I'd like to avoid P2 or Box2d for the sake of performance, since OBB would perfect satisfy my needs.

 

Thanks in advance!

 

UPDATE

 

I started a github project for adding OBB to Phaser. I took the gist by enriqueto and made a little work-around that is available here:

 

https://github.com/t.../OBB-for-Phaser

 

But be aware that it doesn't work as expected yet. Maybe some of you want to contribute  :)

Link to comment
Share on other sites

The Ninja physics system adds slopes and circles to phaser and already exists. It was part of the main build but is no longer maintained due to lack of use/ support. When it was discontinued it could just be plugged back in when needed. I'm not sure if that remains the case with Phaser now but it should be easier to update this than start from scratch. It is still available on GitHub.

This post explains Ninja before it was dropped:

http://www.html5gamedevs.com/topic/4518-explaining-phaser-2s-multiple-physics-systems/

Link to comment
Share on other sites

The Ninja physics system adds slopes and circles to phaser and already exists. It was part of the main build but is no longer maintained due to lack of use/ support. When it was discontinued it could just be plugged back in when needed. I'm not sure if that remains the case with Phaser now but it should be easier to update this than start from scratch. It is still available on GitHub.

This post explains Ninja before it was dropped:

http://www.html5gamedevs.com/topic/4518-explaining-phaser-2s-multiple-physics-systems/

 

I'm a little confused. I can't find any explanation why Ninja was dropped in the topic you linked to. Instead as far as I understand it, it introduces Ninja Physics (keep in mind that this topic is over a year old).

 

I've read in some other posts that Ninja is believed to support rotating bounding boxes, but I guess thats superstition, since I couldn't find any evidence in the docs (and in it's code).

Link to comment
Share on other sites

supporting AABB and Circle vs. Tile collision, with lots of defs for sloping, convex and concave tile types. But that's all it does, it's not trying to be anything more really. 

 

I never used Ninja but it seems that the slopes etc come from defining tiles rather than AABB distance calculations etc.  The N game it came from had 45 degree slopes only so that would support that.  This placed it between Arcade and P2 in capabilities and performance. This offers an alternative method to try/adapt. I only included that link to show its features when it was included in the Phaser build, the reasons for it being dropped are somewhere in the update log but are summarised as low usage - not worth supporting it .  

 

If you try to modify Arcade Physics to allow rotations you are moving away from what makes it so performant towards full Physics like Box2D / P2.  I'm sure you can reach a happy medium to suit your needs though so good luck.

Link to comment
Share on other sites

Honestly I tried using Ninja but it seems to be tailored to games like N+ or meatboy. I have some interesting collision detection code I've written for phaser to support bitmap collision detection if you need help I'll be interested.

Link to comment
Share on other sites

define a bounding box in a sprite using this format:

 

[ x1, y1, x2, y2, x3, y3, x4, y4 ]

 

update this bounding box with the coordinates of the sprite considering its angle

 

and then use this function to calculate collisions of rotated boxes

 

https://gist.github.com/shamansir/3007244

 

If I knew how to correlate the coordinates' positions with the angle of the body, I'd try this out.

Link to comment
Share on other sites

If I knew how to correlate the coordinates' positions with the angle of the body, I'd try this out.

 

just do that on the update method of the sprite:

 

            var cos:number = Math.cos(this.angle * Math.PI / 180);
            var sin:number = Math.sin(this.angle * Math.PI / 180);
                
            this.boundingBox[0] =  this.relativeBoundingBox[0] * cos - this.relativeBoundingBox[1] * sin + this.x;
            this.boundingBox[1] =  this.relativeBoundingBox[0] * sin + this.relativeBoundingBox[1] * cos + this.y;
            
            this.boundingBox[2] =  this.relativeBoundingBox[2] * cos - this.relativeBoundingBox[3] * sin + this.x;
            this.boundingBox[3] =  this.relativeBoundingBox[2] * sin + this.relativeBoundingBox[3] * cos + this.y;
            
            this.boundingBox[4] =  this.relativeBoundingBox[4] * cos - this.relativeBoundingBox[5] * sin + this.x;
            this.boundingBox[5] =  this.relativeBoundingBox[4] * sin + this.relativeBoundingBox[5] * cos + this.y;
            
            this.boundingBox[6] =  this.relativeBoundingBox[6] * cos - this.relativeBoundingBox[7] * sin + this.x;
            this.boundingBox[7] =  this.relativeBoundingBox[6] * sin + this.relativeBoundingBox[7] * cos + this.y;
Link to comment
Share on other sites

As far as I can tell the performance is similar to the Arcade physics.

Collision is detected perfectly fine, but the off bouncing doesn't work properly at the moment. I'm working on that currently :)

Link to comment
Share on other sites

  • 1 month later...
 Share

  • Recently Browsing   0 members

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