Jump to content

Collision acts different based on which side is collided?


Nebulocity
 Share

Recommended Posts

Greetings.  I'm placing objects (rectangle sprites) in my game that enemy sprites will collide with, but the behavior during collision seems odd.  One of two things will happen:

If the enemy sprite collides with the rectangle's sprite from the left or right, the enemy sprite and the rectangle will bounce away from each other. 

But if the enemy sprite collides with the rectangle from the left or right sides, it behaves normally: the enemy sprite and rectangle sprite both die.

Does this make any sense to anyone?  I don't understand why it would do anything but destroy both sprites, but it's only doing that half of the time...

My collision code is here:

Called by:

    game.physics.collide(enemies, rectangle, rectangleKill, null, this);

Function:

    function collideEnemyRectangle(enemy, rectangle)

    {

        console.log("Enemy destroyed.  Id: " + enemies.getIndex(enemy) + '.  Score: ' + score);

        enemy.kill();

        rectangle.kill();

        updateScore();       

    }

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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