Jump to content

Collision: Make sprites immovable and impassable


jonteferm
 Share

Recommended Posts

Hello,

I have a problem with handling the collision between sprites. I have a group of enemies and a player sprite. I want none of the sprites to be able to move trough each others. At first I had the enemy body set to immovable and that disabled the player from pushing the enemy around upon collision. However, when I added more enemies to the group, I found that if the enemy bodies is set to immovable = true - they will be able to walk straight trough each others even if they have an internal collision detection (as that is the case between two immovable bodies). So if i set immovable to false - the enemies will appear solid when colliding with each other, but the player is able to push the enemy. What is it that I have not understood? I just want all the sprites solid.

Link to comment
Share on other sites

If both objects in a collision are immovable, Phaser isn't allowed to separate them (because immovable), so they will pass through each other.

You can try

enemies.setAll('body.immovable', true);
game.physics.arcade.collide(player, enemies);
enemies.setAll('body.immovable', false);
game.physics.arcade.collide(enemies);

 

Link to comment
Share on other sites

On 2017-03-07 at 5:08 AM, samme said:

If both objects in a collision are immovable, Phaser isn't allowed to separate them (because immovable), so they will pass through each other.

You can try


enemies.setAll('body.immovable', true);
game.physics.arcade.collide(player, enemies);
enemies.setAll('body.immovable', false);
game.physics.arcade.collide(enemies);

 

Thanks! That works fine. Pretty obvious, but I did not think of it :P

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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