swervo Posted March 30, 2015 Share Posted March 30, 2015 Hi, This is my first post. I have done a search for this but I haven't found anything that specifically answers what feels like a basic question. I'm developing my first game using phaser, it basically involves a character running along a rope and collecting things. The character jumps up and down and the objects come on at two different heights. It's a pretty basic game. So, what I'd like to know is: Is it possible to have physics bodies pass through one another. Specifically what I'd like is to be able to register the characters collision with the object but then have the object pass through the character and carry on off the screen. By scanning these forums I discovered 'overlap' instead of 'collision' which has helped but the objects still don't pass through the character. I'm aware that this is disobeying the laws of physics! But I had expected that there would be an easy way to do this - I've tried setting the body to null and a few other things but I can't find a solution that works. Any help would be much appreciated. Link to comment Share on other sites More sharing options...
rich Posted March 30, 2015 Share Posted March 30, 2015 Use a processCallback with either arcade.collide or arcade.overlap. If the process returns false then no further collision takes place, thus objects can run through each other happily. Link to comment Share on other sites More sharing options...
swervo Posted March 30, 2015 Author Share Posted March 30, 2015 Thank-you. That looks like just what I'm looking for. One more question though: Is it customary to debounce functions like this? The processCallback still gets called multiple times for each collision (anywhere between 6 and 11 times) or is there a better technique to make sure it only gets called once per collision? Link to comment Share on other sites More sharing options...
swervo Posted March 30, 2015 Author Share Posted March 30, 2015 The answer to my question appears to be yes. I used this function to create a debounced version of the processCallback and all is well. http://davidwalsh.name/javascript-debounce-function Link to comment Share on other sites More sharing options...
rich Posted March 30, 2015 Share Posted March 30, 2015 The processCallback (and collideCallback) will be called once per frame providing that 'collide' is only called once in your update loop, for as long as the objects overlap or collide. So if it takes 6 frames to fully separate the sprites (or for them to no longer be overlapping) then it'll be called 6 times. If they are are separated immediately after 1 frame, it'll get called once. Link to comment Share on other sites More sharing options...
swervo Posted March 30, 2015 Author Share Posted March 30, 2015 Thanks for the clarification Rich. I had a feeling something like that was occurring. Link to comment Share on other sites More sharing options...
Recommended Posts