AlexArroyoDuque Posted March 16, 2014 Share Posted March 16, 2014 In version 1.1.6 it was possible to use overlap in collisions. There is something similar in the physics system p2? Now I use to define collision the "collides" function: collides (group, callback, callbackContext, shape) The problem is that the player can walk over enemies for example. Link to comment Share on other sites More sharing options...
ClonkMobile Posted March 21, 2014 Share Posted March 21, 2014 Hi,this will help you:http://www.html5gamedevs.com/topic/4760-best-way-to-recreate-old-physicsoverlap-using-p2/ interesting would be how to overlap an arcade with an p2 body. Link to comment Share on other sites More sharing options...
Wavertron Posted March 22, 2014 Share Posted March 22, 2014 If you use an Arcade object or the P2 postbroadphase trick, note that will only do overlap at the AABB collision level (ie a rectangle body). How to do precise overlap on polygons and circles still eludes us. Link to comment Share on other sites More sharing options...
valueerror Posted March 23, 2014 Share Posted March 23, 2014 so with a little bit of simple math you can "manually" determine if two bodies are overlapping.. i made a simple example for you to look at here: disclaimer: i guess this is very expensive since you check every object every frame - but i guess you could tweek it to only check visible objects so it would be more performant.. http://test.xapient.net/phaser/overlap2.html THISONE WORKS WITH CIRCLES ONLY ! here is the code of the function:function checkOverlapManually(enemy) { for (var i =0 ; i<enemies.length; i++){ var dx = ship.body.x-enemy.body.x; //distance ship X to enemy X var dy = ship.body.y -enemy.body.y; //distance ship Y to enemy Y var dist = Math.sqrt(dx*dx + dy*dy); //pythagoras ^^ (get the distance to each other) if (dist < shipdiameter+bulletdiameter){ // if distance to each other is smaller than both radii together a collision/overlap is happening dosomething(enemy); } }} Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 24, 2014 Author Share Posted March 24, 2014 Interesting.I would like phaser had overlap with P2 system.Thank you! Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 31, 2014 Author Share Posted March 31, 2014 Hi.I think it's interesting to watch this. Overlap without Physics.http://examples.phaser.io/_site/view_full.html?d=sprites&f=overlap+without+physics.js&t=overlap%20without%20physics Link to comment Share on other sites More sharing options...
valueerror Posted March 31, 2014 Share Posted March 31, 2014 interesting indeed.. i looked into it... the "intersects" function is also available for circles - it does the same thing i did in my function checkOverlapManually(enemy) (but maybe more efficient ) it is also possible to use "intersectsRectangle" to check if a circle and a rectangle overlap.. nice.. this should do it in most cases.. Link to comment Share on other sites More sharing options...
JP91 Posted March 31, 2014 Share Posted March 31, 2014 Broadphase does that with boundingRadiusCheck() and aabbCheck() Link to comment Share on other sites More sharing options...
rodrigogrow Posted April 1, 2014 Share Posted April 1, 2014 Broadphase does that with boundingRadiusCheck() and aabbCheck() Broadphase ? Could you explain more ? Link to comment Share on other sites More sharing options...
JP91 Posted April 1, 2014 Share Posted April 1, 2014 Rich has not yet implemented in Phaser, is not whether it would be useful. ok.. mmm... you can use p2.Broadphase.boundingRadiusCheck(bodyA,bodyB)radius of two bodies overlap,if you uses a Box,p2.Broadphase.aabbCheck(bodyA,bodyB)bodyA overlap bodyB. for example two bodies: //update var bodyA=game.physics.p2.getBody(sprite1), bodyB=game.physics.p2.getBody(sprite2); if(p2.Broadphase.aabbCheck(bodyA,bodyB)){ console.log("ok"); } sorry for the code as shown and I hope to serve you Link to comment Share on other sites More sharing options...
powerfear Posted April 1, 2014 Share Posted April 1, 2014 You can simply use isSensor true to get overlap with p2, works with any convex polygon shape. To clarify if you are loading shapes from a file you will have something like this:{ "someShape": [ { "isSensor": true, //will make the shape overlap rather then collide "filter": { "group": 1, "categoryBits": 2, //some category the shape belong to "maskBits": 1 //what other catagories this shape will react with }, "polygons":[ //polygon data.... ] } ] }This is usually automatically generated using a tool like http://www.codeandweb.com/physicseditor you can use the Phaser exporter along with it, it can be found here Just put it inside your Physics Editor folder (\PhysicsEditor\Exporter\phaser) Or if you want to create simple shape, I believe you can directly set the sensor property to true on the shape you create, like this:var shape = new p2.Circle(...);shape.sensor = true; Link to comment Share on other sites More sharing options...
valueerror Posted April 2, 2014 Share Posted April 2, 2014 thats a nice way to achive overlaps but how would a body that "isSensor" ever collide ? let's say i want my player to overlap with one thing but collide with the other thing.. and the one thing should also collide with all other things except the player... Link to comment Share on other sites More sharing options...
powerfear Posted April 2, 2014 Share Posted April 2, 2014 If you don't need to know when an object overlap, you can use the categoryBits / maskBits system, you can say which categories you want to collide with. If you need to know when you collide and when you overlap, the only thing i can think about would be to have 2 identical shape, one that is a sensor and one that is not. This may decrease your performance greatly thought. Link to comment Share on other sites More sharing options...
Wavertron Posted April 2, 2014 Share Posted April 2, 2014 ........Or if you want to create simple shape, I believe you can directly set the sensor property to true on the shape you create, like this:var shape = new p2.Circle(...);shape.sensor = true; So once you have the P2 sprite set as a Sensor, what function do you use to actually handle the overlap event? Link to comment Share on other sites More sharing options...
powerfear Posted April 2, 2014 Share Posted April 2, 2014 So once you have the P2 sprite set as a Sensor, what function do you use to actually handle the overlap event? Same as for collisionthis.body.onBeginContact.add(this.overlap, this); Link to comment Share on other sites More sharing options...
Recommended Posts