Jump to content

One-side collision detection


Recommended Posts

Hello, while modifying the phaser tutorial_02 code, and using the arcade physics, I discovered that while "dude" collides with the platform while moving from up to bottom, he passes over it while moving from bottom-to-up.

See here a live example:


Is that a problem regarding the Arcade physics?

Link to comment
Share on other sites

The problem is, that you are setting the x & y values of the player directly.


Arcade physics only works if you use the velocity values.

Based on the velocity, the arcade engine moves the sprites itself, and then all collisions work,


You (and I) may wonder, why the collision from above did still work in your example.

This is because the gravity is still on.

(Gravity sets the y velocity to a negative value, the physics collisions happen (that is why it only works on the negative y axis) and then you reset the velocities to 0, so no actual gravity is visible.)


The solution for you (I think you are going for a zelda style movement with no gravity right?) is:


1) set gravity to zero

2) instead of increasing / decreasing the player.body.x & y set the body.velocity.x / y to values like 100 (while keeping your reset to zero where it is now, so that the player stops if no key is pressed)

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.

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.


  • Recently Browsing   0 members

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