CaptKiwi Posted October 10, 2013 Share Posted October 10, 2013 Hi Guys, I'm really enjoying Phaser and getting great results. I have a question about collisions: When two sprites hit each other, the sprites nudge each other, knock them back a little. This would normally be fine, but it is causing the sprite to slowly move in another direction because of the nudge. Is there a way to turn that off the nudging effect so that they collide without any force? Cheers,CaptKiwi Link to comment Share on other sites More sharing options...
4ucai Posted October 10, 2013 Share Posted October 10, 2013 function update() { game.physics.collide(sprite1, sprite2, collisionHandler, null, this); } function collisionHandler (obj1, obj2) { obj1.body.velocity.x = 0; obj2.body.velocity.x = 0; }just set the velocity to 0 CaptKiwi 1 Link to comment Share on other sites More sharing options...
CaptKiwi Posted October 10, 2013 Author Share Posted October 10, 2013 function update() { game.physics.collide(sprite1, sprite2, collisionHandler, null, this); } function collisionHandler (obj1, obj2) { obj1.body.velocity.x = 0; obj2.body.velocity.x = 0; }just set the velocity to 0 Works perfectly :-) Thanks 4ucai!!! Link to comment Share on other sites More sharing options...
rich Posted October 10, 2013 Share Posted October 10, 2013 Just to add that if you don't want a sprite to move when it's collided with, just do this:sprite.body.immovable = true;(you can toggle that boolean at any point in your game too) And just to clarify - an immovable true sprite can still be adjusted via velocity / acceleration like normal, it just doesn't receive any impact velocity. If you want a sprite to NEVER move, including when setting velocity on it, you'd use:sprite.body.moves = false; mariogarranz 1 Link to comment Share on other sites More sharing options...
4ucai Posted October 10, 2013 Share Posted October 10, 2013 Rich answer is more accurate =) Link to comment Share on other sites More sharing options...
Recommended Posts