erikwittern Posted April 5, 2014 Share Posted April 5, 2014 Hello there! I would like to use both, the arcade and the ninja physics system in a small project. I want to use arcade because of some nice functions like "accelerateToObject" and I want to use ninja because it allows for circular bodies. I want to be able to react to the collision of objects, one using the arcade (obj1) and the other using the ninja (obj2) physics system. Using game.physics.arcade.collide(obj1, obj2,...) does not work, because the ninja body does not have a "position" property, as far as I can tell -> I get a corresponding error. Using game.physics.ninja.collide(obj1, obj2,...) does not throw an error, but does not react to collisions also. Is there a way for collision to work in this scenario? A related question: is there a way to render a ninja body? This seems only to work using debug for the arcade system... Link to comment Share on other sites More sharing options...
valueerror Posted April 6, 2014 Share Posted April 6, 2014 try the intersects() method.. it works on sprites without any physics system.. you can even see if a rectangle and a cirle intersect... Link to comment Share on other sites More sharing options...
erikwittern Posted April 6, 2014 Author Share Posted April 6, 2014 Thx for the hint! I am unsure, however, where / how to use this. There is Phaser.Circle.intersects, Phaser.Line.intersects, and Phaser.Rectangle.intersects. If obj1 is an arcade rectangle and obj2 is a ninja body, should I use Phaser.Circle.intersects(obj1, obj2)? And how could I react to an intersection? Link to comment Share on other sites More sharing options...
valueerror Posted April 6, 2014 Share Posted April 6, 2014 uh.. maybe sprite.overlap() is what you need.. you could do a simple if (mysprite.overlap(othersprite)){whatever} Link to comment Share on other sites More sharing options...
erikwittern Posted April 6, 2014 Author Share Posted April 6, 2014 Sprite.overlap() works fine with the bodies from the two systems, but it does not consider that the ninja body is a circle - it treats it like a rectangle. Hm, this seems to be difficult... Link to comment Share on other sites More sharing options...
valueerror Posted April 6, 2014 Share Posted April 6, 2014 hmm.. what about .. phaser.circle <static> intersectsRectangle(c, r) → {boolean} Checks if the given Circle and Rectangle objects intersect. ??? Link to comment Share on other sites More sharing options...
rich Posted April 8, 2014 Share Posted April 8, 2014 Hello there! I would like to use both, the arcade and the ninja physics system in a small project. I want to use arcade because of some nice functions like "accelerateToObject" and I want to use ninja because it allows for circular bodies. I want to be able to react to the collision of objects, one using the arcade (obj1) and the other using the ninja (obj2) physics system. Using game.physics.arcade.collide(obj1, obj2,...) does not work, because the ninja body does not have a "position" property, as far as I can tell -> I get a corresponding error. Using game.physics.ninja.collide(obj1, obj2,...) does not throw an error, but does not react to collisions also. Is there a way for collision to work in this scenario? A related question: is there a way to render a ninja body? This seems only to work using debug for the arcade system... It would probably be easier to just port the accelerateToObject (etc) functions over to Ninja than try to blend the two together! It's something that is on the roadmap, but don't hold your breath for it just yet. Link to comment Share on other sites More sharing options...
erikwittern Posted April 9, 2014 Author Share Posted April 9, 2014 Thanks for the advise! I actually went that way and created a corresponding accelerateToObject function that I now use with P2 physics. Here is my code, if anybody is interested (it is inspired by the same method in the arcade physics system):accelerateToObject: function (obj1, obj2, speed) { if (typeof speed === 'undefined') { speed = 60; } var angle = Math.atan2(obj2.y - obj1.y, obj2.x - obj1.x); obj1.body.force.x = Math.cos(angle) * speed; obj1.body.force.y = Math.sin(angle) * speed;} valueerror 1 Link to comment Share on other sites More sharing options...
rich Posted April 10, 2014 Share Posted April 10, 2014 Nice Link to comment Share on other sites More sharing options...
Recommended Posts