Jump to content

Disable the "bump" when 2 sprites collide ? (Arcade physics)


jeancode
 Share

Recommended Posts

Hello,

I'm learning phaser since 2 days, and I would like to create a puzzle-like game. I'm using tiled to create a map, and you play the game by moving horizontally and vertically some sprites around the grid composed with blocking tiles.

 

All the movable sprites belongs to a group, and move together. Eventually they can collide each other, and I have a problem when this happens : My collision detection with other elements is terrible after that. For example a sprite will have troubles going through some sort of a tunnel (1 row/col surrounded by blocking rows/cols).

 

I think this happens when a sprite bump into another, there is a little momentum (the "bump"), and the sprites don't get their exact position back.

 

Here is what I mean :

 

http://phaser.io/sandbox/YcNywSia

 

After those sprites collide, the debug rendering says everything is correct (the velocity of the sprites is back to 0, the position is normal again).

However, I wrote a console.log to track the velocity of a sprite, and as you can see the velocity doesn't get back to 0 but something like 1*e^-12. So I guess this value is rounded and It's perfectly fine in most cases, but the thing is even if it's not seeable by the human eye, the computer does take this value and the positions of the sprites are a bit off. Hence the weird collisions with other blocks after this type of collision.

 

In the end, I would like to disable this little bump because I don't really need it as my game is fairly simple and doesn't really need advanced collision like momentum.

 

Any help will be appreciated, thank you ! (I'm still learning so chances are I missed something completely obvious :) )

Link to comment
Share on other sites

I don't really know if I understand you correct, but set the velocity to 0 in your collisionHandler function. That should eliminate the 'bump-effect'. 

function collisionHandler (obj1, obj2) {    //  The two sprites are colliding    game.stage.backgroundColor = '#992d2d';    sprite.body.velocity.x = 0;    sprite2.body.velocity.x = 0;}
Link to comment
Share on other sites

Thanks for you reply.

 

This is something I've already tried, unfortunately this doesn't work very well. If two sprites are already next to each other and you move them, they will randomly stop during the movement because somehow the engine detects a collision, thus the callback set their velocity to 0. It's kind of like the physics of our microscopic real world.  ^_^

 

To be honest I think I will remove the arcade physics on these type of sprites and write a movement & collision handler manually in the update loop, because it looks like it's just not suited for this type of movements. It shouldn't be that hard.

Link to comment
Share on other sites

 

 

If two sprites are already next to each other and you move them, they will randomly stop during the movement because somehow the engine detects a collision, thus the callback set their velocity to 0

 

You could make the bodies of the sprites smaller. So they can a little bit overlap without triggering the callback function. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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