Jump to content

Trouble With Ground


fedora
 Share

Recommended Posts

I am having difficulty having the ground stop any object other than player (not even quite sure why player stops).  The other object(s) fall straight through.  

 

I thought it would be a simple as creating another collision group, but when I do so the game does not run.  Here is what I am trying ---

 

 create: function () {            this.physics.startSystem(Phaser.Physics.P2JS);    this.physics.p2.setImpactEvents(true);        this.physics.p2.gravity.y = 1200;     this.world.setBounds(0, 0, 2000, 600);//(x, y, width, height)    this.physics.p2.setBoundsToWorld(true, true, false, true, false);     this.physics.p2.friction = 5;          clouds = this.add.tileSprite(0, 0, 2048, 600, 'clouds');     ground = this.add.sprite(this.world.width/2, this.world.height-24,'ground');    this.physics.p2.enable(ground);     ground.body.static=true;           player = this.add.sprite(350, this.world.height - 150, 'player');    this.physics.p2.enable(player, false);    player.body.setCircle(22);    player.body.fixedRotation = true;    player.body.mass = 4;    player.body.name = 'player';        enemy = this.add.sprite(350, this.world.height - 450, 'enemy');    this.physics.p2.enable(enemy, true);    enemy.body.setCircle(22);    enemy.body.fixedRotation = true;    enemy.body.mass = 4;        var playerCollisionGroup = this.physics.p2.createCollisionGroup();    var enemyCollisionGroup = this.physics.p2.createCollisionGroup();    var groundCollisionGroup = this.physics.p2.createCollisionGroup();    player.body.setCollisionGroup(playerCollisionGroup);    enemy.body.setCollisionGroup(enemyCollisionGroup);    ground.body.setCollisionGroup(groundCollisionGroup);    player.body.collides(enemyCollisionGroup, this.destroyEnemy, this);    enemy.body.collides(playerCollisionGroup);    enemy.body.collides(groundCollisionGroup);
Link to comment
Share on other sites

In case anyone stumbles across this, I figured it out using the following:

 

    var groundCollisionGroup = this.physics.p2.createCollisionGroup();    var playerCollisionGroup = this.physics.p2.createCollisionGroup();    var enemyCollisionGroup = this.physics.p2.createCollisionGroup();    ground.body.setCollisionGroup(groundCollisionGroup);    player.body.setCollisionGroup(playerCollisionGroup);    enemy.body.setCollisionGroup(enemyCollisionGroup);       ground.body.collides(enemyCollisionGroup);     ground.body.collides(playerCollisionGroup);     player.body.collides(enemyCollisionGroup, this.destroyEnemy, this);    player.body.collides(groundCollisionGroup);    enemy.body.collides(playerCollisionGroup);    enemy.body.collides(groundCollisionGroup);
Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

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