tmuecksch Posted June 24, 2015 Share Posted June 24, 2015 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 More sharing options...
enriqueto Posted June 24, 2015 Share Posted June 24, 2015 I have the same problem. When bodies move quickly the arcade physics collision detection doesn't work well. Have you tried to implement the collision detection yourself? shouldn't be difficult. Link to comment Share on other sites More sharing options...
Tilde Posted June 24, 2015 Share Posted June 24, 2015 We all need this, really. Link to comment Share on other sites More sharing options...
tmuecksch Posted June 24, 2015 Author Share Posted June 24, 2015 Hm. Okay. I'm thinking about forking the Arcade physics engine and trying to make this myself. I thought maybe there already is a solution for that. Link to comment Share on other sites More sharing options...
spencerTL Posted June 24, 2015 Share Posted June 24, 2015 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 More sharing options...
tmuecksch Posted June 24, 2015 Author Share Posted June 24, 2015 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 More sharing options...
d13 Posted June 24, 2015 Share Posted June 24, 2015 trying to make this myself. This might help: http://www.flipcode.com/archives/2D_OBB_Intersection.shtml tmuecksch 1 Link to comment Share on other sites More sharing options...
spencerTL Posted June 24, 2015 Share Posted June 24, 2015 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 More sharing options...
rgk Posted June 24, 2015 Share Posted June 24, 2015 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 More sharing options...
enriqueto Posted June 24, 2015 Share Posted June 24, 2015 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 Link to comment Share on other sites More sharing options...
Tilde Posted June 25, 2015 Share Posted June 25, 2015 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 More sharing options...
tmuecksch Posted June 25, 2015 Author Share Posted June 25, 2015 Okay guys. I got me some literature on how to detect collision and will try to create some fix.As soon as I have a solution I will check back with you here. Link to comment Share on other sites More sharing options...
enriqueto Posted June 26, 2015 Share Posted June 26, 2015 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 More sharing options...
tmuecksch Posted June 26, 2015 Author Share Posted June 26, 2015 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/tobiasmuecksch/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 More sharing options...
tmuecksch Posted June 26, 2015 Author Share Posted June 26, 2015 I need some help.Does anyone know how to calculate bouncing between two collided OBB objects? Link to comment Share on other sites More sharing options...
rgk Posted June 28, 2015 Share Posted June 28, 2015 tmuecksch, awesome job I will be checking it out, how is the performance? Link to comment Share on other sites More sharing options...
tmuecksch Posted July 1, 2015 Author Share Posted July 1, 2015 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 More sharing options...
Tilde Posted July 3, 2015 Share Posted July 3, 2015 Thanks a lot! I think there should be a built-in derivative of Arcade or something like this. Link to comment Share on other sites More sharing options...
Tilde Posted August 3, 2015 Share Posted August 3, 2015 Here's a post letting you know I'm still interested in this project! Link to comment Share on other sites More sharing options...
Tilde Posted August 7, 2015 Share Posted August 7, 2015 I also have some questions about your implementation and how it works. Are you still working on this? Link to comment Share on other sites More sharing options...
Recommended Posts