Jump to content

Check for collision after partial overlapping


Recommended Posts

Hi there,

first of all: excuse my english ;)

I am a newcomer in the world of phaser but I'm quite addicted. After some tutorials I'm making my first steps with trail'n error. Right now I'm looking for a solution for this problem:

I've got a player and a object (a table for example). It's that classical 2D RPG/Adventure setting so the player should collide with the object, but doesn't stop with his head on the bottom of the object. Instead he should overlap with a part of his body.

From that behaviour:


to that:


After an hour of vainly internet reaseach I hope you guys can help me out.
I'm using the Arcade Physics and think I have to operate with customSeparateY. Right now my player collides on the left and right side of the object but can walk through from the bottom and above.

That's my create:

create: function () {
    object = game.add.sprite(100, 150, 'object');
    object.frame = 2;
    player = game.add.sprite(200, 200, 'player');


    player.body.collideWorldBounds = true;
    object.body.immovable = true;

    player.body.customSeparateY = true;

And in the update function I check for collision between player and object:

game.physics.arcade.collide(player, object);

I found that physics.arcade.overlap method but at this moment I don't know how to use it correctly. Since I think there is some important stuff I don't see right now I'm looking for help. ;)

Thanks in advance

Link to comment
Share on other sites


  • Recently Browsing   0 members

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