Jump to content

Check for collision after partial overlapping


user.src
 Share

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:

 scene1.png.a5ad3d1a8201b97f5409dd400fe45

to that:

scene2.png.87c5e7f9e115881ef14d1afecd44f

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

    game.physics.arcade.enable(player);
    game.physics.arcade.enable(object);

    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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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