Jump to content

How to disable collision for body


EgorkZe
 Share

Recommended Posts

You can use the processCallback in the collide function. The 4th parameter is a function which, if it returns true, will allow the collision to happen, otherwise the collision will be ignored. This allows you to keep the body enabled for velocity calculations etc, but just temporarily disable collisions between these two objects. If you set enableObstacleCollide to true, the obstacle will begin colliding with the player again:

var enableObstacleCollide = false;game.physics.arcade.collide(player, obstacle, function() {  // do any collision stuff here}, function() {  if (enableObstacleCollide) {    return true;  }  return false;});
Link to comment
Share on other sites

Mysprite.body.data.shapes[0].sensor=true;

Written out of my head.. I hope without errors ;)

This should set the body as sensor.. Still sensing the collision so you could start an onbegincontact event, but not colliding

But the body falling though the all objects. I want body not colliding only my hero body

Link to comment
Share on other sites

interesting.. i've never tried to set gravity scale on a sensor..  but since you are not going to use sensor anyway this shouldn't be a problem..  use collisiongroups for fine-grained declaration of what collides with what instead of the sensor.. i thought you wanted something that never collides  :)

Link to comment
Share on other sites

  • 5 months later...

Nice.  

 

Using the following: 

game.physics.arcade.overlap(bullets, aliens, collisionHandler, null, this);

how do I structure the syntax to do the following:

 

var enableObstacleCollide = false;        game.physics.arcade.overlap(bullets, aliens, collisionHandler, null, this){        }, function() {          if (enableObstacleCollide) {            return true;          }          return false;        });

Not quite there is it... o.O! 

 

 

I basically want to switch collision off once the aliens been hit, cause in my version he hangs around a bit.


It's strange tho, when the alien has been hit once, I'm changing it's group, so it should not be affected by this at all once the aliens been moved to a different group. But it is o.O :(

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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