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

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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.