Sign in to follow this  

Problems with Collision between Player and Enemy

Recommended Posts

I was experimenting with spawning enemies from the right side of the game's canvas. The player, being on the left side shoots the enemies coming from the right. I have a problem though. When the player shoots the enemy while it spawns a couple pixels away from the right side of the screen, the enemy dies (I made a collision handler), but the problem comes when the enemy reaches halfway past the spawn point. It seems that if the enemy gets too close to the player the bullets don't seem to effect the enemy at all. The enemy seems to only die a couple of pixels away from the right side of the screen. Here is how I have things set up:


Currently using Phaser 2.0

//Create function with bullets        bullets =;        bullets.enableBody = true;        bullets.physicsBodyType = Phaser.Physics.ARCADE;        bullets.createMultiple(50, 'bullet');        bullets.setAll('anchor.x', 0.5);        bullets.setAll('anchor.y', 0.5);        bullets.setAll('outOfBoundsKill', true);//UPDATE, clone, this.enemyKill, null, this);//Method used to spawn enemies//I call a function named 'lvl1' that spawns enemies from the right side of the screen levelOne: function() {        this.lvl1 =;        this.lvl1.start();        this.lvl1.onComplete.add(this.watchCounter, this);        this.lvl1.repeat(Phaser.Timer.SECOND * 2, 10, this.enemyOne, this);    },//This function uses the Phaser timer method to call a function to create enemies 10 times every 2 seconds//The function for the enemy is down below:enemyOne: function() {        clone = + 100, (100 + spawnLimit), 'CloneOne');        //I "bottlenecked" the spawn area to be between a specific, Phaser.Physics.ARCADE);        clone.enableBody = true;        clone.anchor.setTo(0.5, 0.5);        clone.body.velocity.x = -110;        clone.animations.add('run', [11, 10, 9, 8, 7, 6], 10, true);'run');    },//Here is the collision handler 
enemyKill: function(bullet, clone) {        bullet.kill();        clone.kill();    }//Here is the players fire methodfire: function() {        if ( > nextFire && bullets.countDead() > 0) {            var shoot ='shoot');  ;            nextFire = + fireRate;            bullet = bullets.getFirstDead(false);            bullet.body.velocity.x = 350;            bullet.reset((player.x + 65), (player.y + 20));            bullet.rotation =, 300);        }    },
EDIT: I just did some debugging using the line of code below and discovered that when the enemy reaches halfway across the screen the collision box literally disappears. How can that be?
EDIT: The only "enemy" that takes collision is the last enemy that is spawned. 
    render: function() {;  ;     }

Thank you all in advance. 

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.