Jump to content

Physics bodies stick when colliding from the side


Natman
 Share

Recommended Posts

It seems that using Arcade Physics, Ninja Physics, or P2 Physics, my game has the same problem: when two bodies are touching on the side, their gravity is slowed significantly. Specifically, the player can jump against a wall and will take a really long time to fall down the side. Has anyone else noticed this problem? How do I fix/work around it?

 

Edit: The problem is even worse because the player can actually jump again while stuck against the wall. I'm using body.touching.down to check if the player should be able to jump, but it allows this buggy behavior.

Link to comment
Share on other sites

I experience the same problem running this example:

http://examples.phaser.io/_site/view_full.html?d=ninja%20physics&f=ninja+aabb+vs+aabb.js&t=ninja%20aabb%20vs%20aabb

 

I uploaded my code to my site, and renamed index.html to game.html so you can browse the whole directory at this link:

http://nathanielnelson.com/webgames/BricketySplit/

 

Or you can just look at the repo on Github, if that's easier for any reason: https://github.com/LostCodeStudios/BricketySplit

 

I might be using the wrong Phaser build. I don't remember where I found the one I'm using, lib/phaser.js. Where do I find the official/recommended version of that  file?

 

To replicate the problem in my game: I think you have to actually jump into another body from the RIGHT side, so wait around on the right side of the screen until enough bricks fall, then just start jumping into the wall from the right. You should experience slow falling, and be able to jump repeatedly or hold Z and have your character just move upward continually.

 

This problem happens not only with the player but with the bricks when they collide with themselves. I actually modify the size of each individual brick to give them space so they're not actually touching each other horizontally. I do this with the following code in brick.js:

this.sprite.body.setRectangle(width - bodyWidthMargin, height - bodyHeightMargin, bodyWidthMargin / 2, bodyHeightMargin / 2);this.sprite.body.x = x;this.sprite.body.y = y;this.sprite.body.gravity.y = gravity;

I have to reset x, y, and gravity for bricks after I make these modifications because for some reason setRectangle() moves them to (0, 0) and changes their gravity. I couldn't find a better way to do this.

Link to comment
Share on other sites

i've got the very same problem..  and like rich said..  there is velocity applied...   in my platformer when you jump to the side of another object and keep pushing the button to move into the direction of the object you will stick on it...

 

the only workaround i found is creating a contact material with 0 friction ..but that's definitely not wanted on the upper surface of the object.. just on the sides...  so NO.. i still don't know how to prevent this..  i can't just stop the input actions when colliding to the right... with p2 i even don't know how to find out where the body is touching.. it seems not to be implemented right now..

 

demo game where i try to solve all my "basic problems":   try to jump on the green pipes on the left.. > stick on it   .. jump on the ice material to the right (0 friction) it works as expected...

http://test.xapient.net/phaser/ALL/

Link to comment
Share on other sites

I added a check to make sure the player wasn't touching anything on the left or right before setting its velocity, but this didn't fix the problem. I know the player has no velocity (except gravitational) when this problem occurs. I have also verified that the problem only occurs when the player hits another body from the right side.

 

I pulled the Phaser repo, took the latest phaser.js from the build directory, and tried using it in my project to see if it was a version problem. After I did this, my game would toss errors whenever I tried to access the body of a sprite. Every sprite's body was undefined. In create() I tried calling game.physics.startSystem() to see if that was the problem, but this didn't fix it.

Link to comment
Share on other sites

so i made a few tests and tried a workaround..

 

workaround:

find out if the player is touching left or right (or ground) and then (if touching left or right) apply a material that has no friction at all in contact with the other object  or apply the default material when touching only on ground.

 

this "should" work.. but it doesn't..  at least not all the time..  you can see that for some reason the player thinks to be touching DOWN even when up in the air and only touching to the left..   the moment touchingDown comes true - the player sticks.. if touchingDown stays false (as it should be) the player slides down because of the applied material with no friction...

 

so another question remains.. why does my p2 physics body  "think" it is on the ground when there is no ground? 

 

you can try it here again.. i added some debug texts...  http://test.xapient.net/phaser/ALL/

 

run to the left and then jump while continue running to the left.. it will work - you slide down

run to the left and then jump and then press the button to start running to the left - you will stick eventually

 

EDIT:  checkleft or right before applying velocity is a good idea!  to bad it didn't help..  it seems like this is a bug after all 

in my platformer this actually helps a little.. the player falls down.. but it leads to unwanted behaviour when jumping right beside (touching) an object..  for the platformer the material approach is very good but it doesn't work reliable for some reason :(

 

EDIT2:  i'm sorry.. i just found out that you have this problem with ARCADE physics..  so it maybe totally unrelated to mine..  didn't want to hijack your thread..

Link to comment
Share on other sites

I'm pretty sure the problem happens in all physics systems, but I am using Arcade physics in my game, yeah.

Another question: If I want to use circular bodies in my game, can I do that with Arcade physics? If not, which physics system SHOULD I be using?

Link to comment
Share on other sites

Bodies have no concept of 'touching' on a specific face in P2, because a single body might be made up of many different shapes, any number of which may or may not be touching another shape in another body from a completely different angle! Therefore it is, and can only be, something that your game deals with directly. It's not something Phaser could ever determine automatically.

 

In ArcadePhysics however because it's a purely AABB system we DO know when things are touching, and the 2.0.1 update should resolve that quite happily. There are no Circles in ArcadePhysics. If you need Circles you need to use something else (P2 or Ninja maybe).

Link to comment
Share on other sites

so do you have any idea how one could solve this "player sticks to the side of objects" problem for platformer games using p2 ?  

 

i have another description of the problem here...   http://www.html5gamedevs.com/topic/4837-p2-body-seems-to-be-touchingdown-but-up-in-the-air-next-to-a-wall/

and i still don't know how to solve it..  even with contactmaterials and friction 0 the player sometimes sticks to walls instead of sliding down..

a force is of course applied but gravity should do it's thing and bring the body down - slowly but down..    

 

IMHO it's no explanation that it "has to be this way as long as you move forward in the direction of the wall"  because gravitation is also moving you against the ground and still you are able to move to the right if you apply any force..

Link to comment
Share on other sites

  • 3 weeks later...
Any news on this? 

My player is still being attached to the map tiles... 

I have seen the examples:

 


 

I used the contact like @ValueError but I can not fix it.

Link to comment
Share on other sites

I've been chatting to Stefan (p2 author) about this and he's basically said that the sprites aren't sticking to the sides, they're stopping where the bodies join (or where 2 tile bodies join in a tilemap). i.e. there's a micro sized ledge there. They never actually stick against perfectly flat walls. The images in this thread explain it better:

 

http://www.roguekiwi.com/blog/2011/building-tilemap-collision-bodies

 

There are a few options:

 

1) Don't use a rectangle for the player object body. I've seen some solutions use a chamfered box, or a capsule (with rotation disabled) so there are no penetrating edges (i.e. the corners are smooth).

 

2) Find another way to describe the level geometry, i.e. the way the collision bodies are built in the example above.

 

3) Both of the above together!

Link to comment
Share on other sites

hello rich.. thx for the update on this!

 

my player already has a circle body..  so i quickly created a "wall" without tiles (just one big plain sprite) and it stopped sticking to it..  fine

 

BUT the moment i apply ANY friction to this wall (with materials) it starts sticking to it again .. this time to the sides not to some gaps between tiles..

 

so it seems i can not have the same material for the sides as for the top of a platform.. that's a real show stopper because it makes it very difficult to build a working environment..   even if i could assign a different material to each side of a rectange.. which would be some sort of workaround

 

 in the case of a tilemap there is still another problem.. 

how would i create ONE physicsbody out of all tiles of a layer ?

 

for now i do this:

layerice_tiles = game.physics.p2.convertTilemap(map, layerice);for (i=0; i<layerice_tiles.length; i++){        layerice_tiles[i].setCollisionGroup(groundCG);        layerice_tiles[i].collides([playerCG,fireballCG,powerupsCG,enemyGroundCG]);        layerice_tiles[i].setMaterial(iceMaterial);}

this creates an array of bodies and each body gets it's material an CG assigned..   so even for NOfriction tiles there is still the "sticky" problem because of the "little gaps" between the tilebodies.. 

 

:(

 

this problem is not there in arcade physics and there are only rectangles...

Link to comment
Share on other sites

  • 4 months later...
 Share

  • Recently Browsing   0 members

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