EgorkZe Posted November 14, 2014 Share Posted November 14, 2014 I want to create the obstacle in my game, which will be moved to the player side, and i want to disable collisions from obstacle's body, because it move my player's body to the left. How can i do it? Help me! Link to comment Share on other sites More sharing options...
lewster32 Posted November 14, 2014 Share Posted November 14, 2014 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;}); Tilde and ChrisyChris 1 1 Link to comment Share on other sites More sharing options...
EgorkZe Posted November 14, 2014 Author Share Posted November 14, 2014 Ou, sorry, i forgot to tell , i use p2 physic, and i needed to get collision's event but not move the player's body Link to comment Share on other sites More sharing options...
lewster32 Posted November 14, 2014 Share Posted November 14, 2014 Oh, not sure how you do this in P2. Presumably there's an equivalent to overlap? Link to comment Share on other sites More sharing options...
valueerror Posted November 14, 2014 Share Posted November 14, 2014 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 Link to comment Share on other sites More sharing options...
EgorkZe Posted November 17, 2014 Author Share Posted November 17, 2014 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 collidingBut the body falling though the all objects. I want body not colliding only my hero body Link to comment Share on other sites More sharing options...
lewster32 Posted November 17, 2014 Share Posted November 17, 2014 I think this may be what collision groups are for if I'm not mistaken? http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=collision+groups.js&t=collision%20groups Link to comment Share on other sites More sharing options...
EgorkZe Posted November 17, 2014 Author Share Posted November 17, 2014 How can i disable gravity for the sprite's body? Link to comment Share on other sites More sharing options...
valueerror Posted November 17, 2014 Share Posted November 17, 2014 sprite.body.data.gravityScale = 0 ;@lewster: you are right.. thats what collisiongroups are for lewster32 1 Link to comment Share on other sites More sharing options...
EgorkZe Posted November 17, 2014 Author Share Posted November 17, 2014 @valueerror it doesn't work( "sprite.body.data.gravityScale = 0 "; Link to comment Share on other sites More sharing options...
EgorkZe Posted November 17, 2014 Author Share Posted November 17, 2014 this.body.data.shapes[0].sensor=true;this.body.data.gravityScale = 0; it doesn't work( but if i put only one stringthis.body.data.gravityScale = 0;it work It's a bug? Link to comment Share on other sites More sharing options...
valueerror Posted November 17, 2014 Share Posted November 17, 2014 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 More sharing options...
GourmetGorilla Posted May 8, 2015 Share Posted May 8, 2015 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 More sharing options...
Recommended Posts