Jump to content

How to on three bodies collision?


Recommended Posts



I'd like to kindly ask for your advice with a problem I encountered in my game.

(I'll try to describe the situation with pictures to make it more clear.)


Currently I'm using ARCADE physcis. I'm having tree bodies which I need to collide in some way.

These three are as follow: player (cyan rectangle), platform (blue rectangle) and wall (purple rectangle).



My update function looks like this:

update: function() {// collision teststhis.physics.arcade.collide(this.player, this.walls);this.physics.arcade.collide(this.player, this.platforms);this.movePlayer(); // handles player controls}

Checking collisions between player and walls (phaser.group, walls.body.immovable = true) and player and platforms (phaser.group, platforms.body.immovable = true).


Both platforms and walls have their body set to immovable (true) to make sure that player doesn't push it away. While walls are not moving (no velocity), platforms are moving with velocity.x. When player lands on the platform it moves with the platform (that's desired outcome, so it's ok).


Collisions between player x walls and player x platforms work fine.


Problem comes when player 'rides' platform and it takes him to side where the player should collide with walls and it should keep him in world but that doesn't happen. When platform moves player to walls, player x walls collision doesn't detect it at all thus player leaves the screen together with the platform it rides on.


Is there a way to make player riding the platform to collide with walls as well? Or some other way how to handle this in phaser?


Here is the picture for this situation:




I tried adding a function to player x platforms collision which checks whether player is overlapping with walls and if it is than players X position is set to be next to wall, which doesn't work exactly as expected. I suspect that the platform moving the player along proceeds after this test and thus moves the player a bit forward leaving player inside the wall on one the left side (in the picture I call it OVERLAP in red) or not touching the wall on the right side (in the picture I call it GAP in red.


Here is the picture which describes this situation.



I moved the condition from player x platform collision to update function (beginning and end of the phaser state update function) but the result is the same. I was looking if there is a way to do some stuff after update function goes off but I coulnd't find anything to help me with this.



I hope I stated my problem correctly. I'd really appreciate if anyone could give me some advice which I'm thankful for.





Solved, changing the order of collision detections did the trick, I'm so bad... :-)

Link to comment
Share on other sites


  • Recently Browsing   0 members

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