cauldron Posted January 4, 2018 Share Posted January 4, 2018 Hello everyone, Do you know if it is possible to add a custom collision handler for world bound collisions with the arcade physics system? I know that the onWorldBounds signal exists, but from what I've tried it seems to be fired at the beginning of the collision and it does not prevent the velocity changes from being made further down the road. Am I missing something? For clarification what I am trying to achieve is to add random direction displacement to the velocity of a ball each time it collides with the world bounds. Thank you for time. Link to comment Share on other sites More sharing options...
samme Posted January 4, 2018 Share Posted January 4, 2018 I think onWorldBounds is triggered after the body has changed direction (bounced), so you could just modify the velocity there. Or you could overwrite Phaser.Physics.Arcade.Body.prototype.checkWorldBounds. Link to comment Share on other sites More sharing options...
cauldron Posted January 6, 2018 Author Share Posted January 6, 2018 On 1/5/2018 at 7:59 AM, samme said: I think onWorldBounds is triggered after the body has changed direction (bounced), so you could just modify the velocity there. Or you could overwrite Phaser.Physics.Arcade.Body.prototype.checkWorldBounds. First of all thank you for taking the time to reply. Upon further investigation you are indeed right, the onWorldBounds event is triggered after the change of velocity due to the bounce. There is still one thing I don't understand though: the velocity of the physics body is indeed updated before the onWorldBounds event is triggered, however that does not seem to be the case for the velocity of the physics body. The velocity seems to be only updated some time after the collision takes place. Why is this the case? Shouldn't the angle of the physics body always depend on its velocity or am I missing something? I've created a small runnable example to better demonstrate what I mean: https://codepen.io/anon/pen/QaOGMO Link to comment Share on other sites More sharing options...
samme Posted January 6, 2018 Share Posted January 6, 2018 I think that's a quirk of the Arcade Physics engine. It's based on the preUpdate/postUpdate cycle, and body.angle is updated only during preUpdate. It's not updated immediately after sprite–sprite collisions either. You can calculate and update the value yourself in the callback. Link to comment Share on other sites More sharing options...
cauldron Posted January 7, 2018 Author Share Posted January 7, 2018 9 hours ago, samme said: I think that's a quirk of the Arcade Physics engine. It's based on the preUpdate/postUpdate cycle, and body.angle is updated only during preUpdate. It's not updated immediately after sprite–sprite collisions either. I see, thank you for the clarification. 9 hours ago, samme said: You can calculate and update the value yourself in the callback. Yeah that's what I did in the end and I am now able to get the behaviour I wanted originally. In any case thank you for taking the time to look into my issue, it certainly saved me quite a bit of time. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts