Jump to content

Group Collisions


Heppell08
 Share

Recommended Posts

This is probably going to be one of them moments that i overlooked something but i just need some help with group colliding.

I've been adding in my enemies and I'm satisfied with the create code I'm using for them. Everything is still at a basic level for the whole game idea. Problem is, the enemy is spawned in perfectly without issue. Problem: the enemies spawn and only collide with the world bounds and not the platform group created. There is a single enemy who collides with the platform but i need them all to collide with the platform group.

Heres some code that may be useful:

// in createenemies = game.add.group(platforms);    for(var i = 0; i < NumofBots; i++)    {        createBot();    }// updategame.physics.collide(enemybot, platforms);// spawn functionfunction createBot(){        enemybot = game.add.sprite(this.x,this.y,'robot1');                this.x = game.world.randomX;        this.y = 100; // purposely ABOVE the platform group        this.maxSpeed = 75;        this.minSpeed = -75;        var rndSpeedY = Math.random()*(this.maxSpeed - this.minSpeed+1)-this.minSpeed;        var rndSpeedX = Math.random()-(this.maxSpeed - this.minSpeed+1)-this.minSpeed;        enemybot.animations.add('walk');        enemybot.animations.play('walk', 10, true);        enemybot.anchor.setTo(0.5,0.5);        enemybot.body.collideWorldBounds = true;        enemybot.body.velocity.x = rndSpeedX;        enemybot.body.velocity.y = rndSpeedY;        enemybot.body.gravity.y = 9.6;}

Any ideas?

 

If i set the collide to groupname enemies i get:

Uncaught TypeError: Cannot read property 'exists' of null

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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