Sign in to follow this  
jonteferm

Collision: Make sprites immovable and impassable

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.

Share this post


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

 

Share this post


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

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.