Jump to content

Phaser Physics Body's Teleporting Into Eachother


JordanSchuetz
 Share

Recommended Posts

Hello,

I'm working on a realtime multiplayer game and I'm running into a problem with the physics that I'm unsure how to correct.  

Basically when one player jumps on top of the other from a high distance, it pushes the other player through the platform and the player gets stuck there.

Here is the code for the platforms:

PlayState._spawnPlatform = function (platform) {
    let sprite = this.platforms.create(
        platform.x, platform.y, platform.image);

    // physics for platform sprites
    this.game.physics.enable(sprite);
    sprite.body.allowGravity = false;
    sprite.body.immovable = true;
    this.game.debug.body(sprite);
};

And here is the code for the players:

PlayState._spawnCharacters = function (data) {
        this.hero = new Hero(this.game, 10, 10);
        this.hero.body.bounce.setTo(0, 0);
        window.globalMyHero = this.hero;
        window.globalOtherHeros = this.otherHeros = new Map();
        this.game.add.existing(this.hero);
        sendKeyMessage({});

};

And here is the collide function between the platform and all of the global players:

this.game.physics.arcade.collide(otherplayer, this.platforms, null, null, this);

Does anyone have any recommendations on how I can make the players not get stuck in other physics objects? Thank you for the help.

Screen Shot 2017-04-17 at 3.13.56 PM.png

Link to comment
Share on other sites

Hi so I wasn't able to find a great solution, however I came up with a little hack that works okay: 

 

 var collidePlayer = this.game.physics.arcade.collide(otherplayer, this.hero, null, null, this);
            if(this.hero.y > 526){
                this.hero.position.set(this.hero.x, 525);
                console.log("set")
            }else if(otherplayer > 526){
                this.otherplayer.position.set(otherplayer.x, 525);
                 console.log("set2")
            }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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