Jump to content

Phaser.Physics. Arcade collide method bug or not expected behavior


Recommended Posts

Well there is some additional info for the bug to be reproduced ;)


1. Sprite 1 a paddle - has this (control with following mouse )

paddle.x = game.input.worldX; 

2.  The bug is that there is no collision detected when the two sprites are going in the same direction like:


sprite1--->   and   sprite2--->  if they are in opposite sprite1--->   and   <---sprite2 there aren't any bugs.


3. I stumbled on a fix but I don't understand why it works :P and there is some paddle shaking/twerk 


In the paddle update if I set: paddle.body.velocity.x = 200;  // this fix the bug and collisions are checked


!!! It works only if the paddle velocity is bigger then the ball velocity.



There isn't such a problem when:


- the control is with keyboard keypress and 

paddle.body.velocity.x = +paddleSpeed;

- the paddle is set to "auto move" like this 

paddle.body.velocity.x += paddleSpeed;

Here is uploaded and version of my breakout implementation:




I've done a set up for easy bug reproduction.


Some control hints: press "B" to switch from keyboard control to mouse control

also try with uncommented 362 line paddle.body.velocity.x = 200;  and also with a

paddle.body.velocity.x = 20; //a smaller then the ball.


Just move the paddle and see how when you hit the ball when the ball is moving left there isn't a collision.


And overall question is there some logic with velocity checks and if a body has less velocity then other body the collision isn't processed... ??

Link to comment
Share on other sites

I suspect that what's happening is that the body has no velocity because you're positioning it via sprite.x and not sprite.body.x, so the physics system will effectively skip the body for separation as it has a zero delta value, so basically isn't moving. Even when using the mouse you should still set body velocity at the moment. There was actually some code in the Body class to check the Sprite itself for delta values (if the Body had none) but I've not worked through that far enough yet.

Link to comment
Share on other sites

I'll mark the topic as solved but i want to add some more info about future me and other future "victims". :P




1. When you have collision it's almost a rule of thumb to update body.x instead .x property of the sprite.


2. If you use:  paddle.anchor.setTo(0.5, 0); //center anchor/origin to the middle of the paddle


and then you want to set the sprite position acording to mouse cursor

instead of doing this:

paddle.x = game.input.worldX

or this:

paddle.body.x = game.input.worldX

you should do this:

paddle.body.x = game.input.worldX - paddle.body.halfWidth;


Happy coding! :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

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