Jump to content

Phaser Physics Body's Teleporting Into Eachother


Recommended Posts


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
    sprite.body.allowGravity = false;
    sprite.body.immovable = true;

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();


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);
            }else if(otherplayer > 526){
                this.otherplayer.position.set(otherplayer.x, 525);


Link to comment
Share on other sites


  • Recently Browsing   0 members

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