Mike Posted October 30, 2013 Share Posted October 30, 2013 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 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: http://mihail.ilinov.eu/games/PhaserBreakoutCollisionVelocityBug/ I've done a set up for easy bug reproduction. Some control hints: press "B" to switch from keyboard control to mouse controlalso try with uncommented 362 line paddle.body.velocity.x = 200; and also with apaddle.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 More sharing options...
Mike Posted October 30, 2013 Author Share Posted October 30, 2013 Ahh I just made another buggy example http://mihail.ilinov.eu/games/phaserExamples/examples/_site/view_full.html?d=games&f=breakout.js&t=breakout Аlso you can open the console F12 and see some additional console.logs of collisions happening and not happening. Link to comment Share on other sites More sharing options...
rich Posted October 30, 2013 Share Posted October 30, 2013 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 More sharing options...
Mike Posted November 1, 2013 Author Share Posted November 1, 2013 I'll mark the topic as solved but i want to add some more info about future me and other future "victims". So: 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 cursorinstead of doing this:paddle.x = game.input.worldXor this:paddle.body.x = game.input.worldXyou should do this:paddle.body.x = game.input.worldX - paddle.body.halfWidth; Happy coding! Link to comment Share on other sites More sharing options...
rich Posted November 2, 2013 Share Posted November 2, 2013 Please never set a numerical value (like anchor) to null. If its meant to be 0 then set it to 0. Link to comment Share on other sites More sharing options...
Mike Posted November 2, 2013 Author Share Posted November 2, 2013 Yep, fixed it in my code and above too. Link to comment Share on other sites More sharing options...
Recommended Posts