Jump to content

[Arcade] Collisions not detected when sprite spawns inside another sprite


mhoff
 Share

Recommended Posts

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:

working.gif

 

Shots spawning inside the enemy do not collide:

not_working_1.gif

 

Walking inside the enemy with charging bullet does not collide. He has to move inside the bullet to trigger the collision:

 not_working_2.gif

 

You can look at the code and reproduce it yourself on http://hf.mhoff.net/lolshooter/

Edited by mhoff
Game fixed
Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

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