Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Collision of arcade and ninja bodies


erikwittern
 Share

Recommended Posts

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

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

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

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;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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