Sign in to follow this  
EgorkZe

How to disable collision for body

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;});

Share this post


Link to post
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

Share this post


Link to post
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  :)

Share this post


Link to post
Share on other sites

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 :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.