mhoff Posted April 29, 2016 Share Posted April 29, 2016 (edited) Hello fellow coders, I'm a beginner with Phaser and still struggling with the arcade physics. Problem is that collisions are not detected when my bullet has spawned inside the target. I have the following setup: A unit (= sprite) can charge and fire bullets (= sprite). A charging bullet is spawned directly in front of the unit via adding it as a child. The bullet grows over time. Releasing the fire button removes the child bullet, adds the bullet to world, translates its coordinates and fires it in the intended direction. On creation, the bullet is added to an array of bullets which are collided against all units. This means, also charging bullets should collide. If the bullet did spawn outside the enemy unit everything works: Charging bullets do collide correctly, as well as released bullets. (Except for walking inside an enemy while charging a bullet) But if the bulled did initially spawn already inside the enemy unit no collision is triggered for most cases. Only when the enemy unit walks inside the bullet the collision is detected. Please see the attachd GIFs. Correct: Shots spawning inside the enemy do not collide: Walking inside the enemy with charging bullet does not collide. He has to move inside the bullet to trigger the collision: You can look at the code and reproduce it yourself on http://hf.mhoff.net/lolshooter/ Edited April 29, 2016 by mhoff Game fixed Link to comment Share on other sites More sharing options...
mhoff Posted April 29, 2016 Author Share Posted April 29, 2016 I could solve the problem myself. arcade.collide takes up to 5 arguments: collide(object1, object2, collideCallback, processCallback, callbackContext) The processCallback is called when two objects intersect. Subsequently, if the processCallback evaluated to true, the collideCallback is called when also some movement against each other could be detected. In my case, the movement was not present. Therefore collideCallback was not called in the buggy situations above. But in all situations the processCallback has been called as expected. Therefore, I simply put my collision handling in there and everything is fine (for now). Link to comment Share on other sites More sharing options...
Recommended Posts