Jump to content

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

  • 5 months later...



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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