Legomite

Prevent arcade physics bodies from overlapping

Recommended Posts

I have a block based game that requires separated physics bodies, which is why I can't merge a wall of five bodies into one.

It appears like the player could still hit the floor in-between the blocks, if the player is forcing itself towards that direction, which makes me think that the bodies are slightly overlapping and causing this. I'm using arcade physics. Is there a way to avoid this?

 

A video here shows the player executing the bug on the top of the tower. He's jumping on the wall, eventually getting over it.

 

Share this post


Link to post
Share on other sites

As far as I know; that's just an unfortunate side effect of having a rectangular character body and rectangular stacked bodies for walls. The corner of your character's body is getting caught on the edge, as when you are telling it to go in that direction it is slightly and then being bounced back (usually), but in this case it thinks it's on the floor and stays there.

 

If you make your character a capsule body, or give it rounded corners, that will not happen (https://phaser.io/docs/2.6.2/Phaser.Physics.P2.Body.html#addCapsule for example).

Share this post


Link to post
Share on other sites
1 hour ago, UncleAcid said:

As far as I know; that's just an unfortunate side effect of having a rectangular character body and rectangular stacked bodies for walls. The corner of your character's body is getting caught on the edge, as when you are telling it to go in that direction it is slightly and then being bounced back (usually), but in this case it thinks it's on the floor and stays there.

 

If you make your character a capsule body, or give it rounded corners, that will not happen (https://phaser.io/docs/2.6.2/Phaser.Physics.P2.Body.html#addCapsule for example).

Is there a way to do this in arcade physics?

Share this post


Link to post
Share on other sites

Aside from manually pushing your character away from the wall if those conditions are met (touching right and bottom), which I would expect to look kinda jittery and unpleasant, I don't believe so as arcade physics is limited to bounding boxes.

 

But I've never used arcade physics enough to encounter the issue, just with p2, so I don't know for sure.

Share this post


Link to post
Share on other sites
28 minutes ago, samme said:

It's hard to know without using `game.debug.body()` (or samme/phaser-plugin-debug-arcade-physics!).

Things you can try:

  • `game.physics.arcade.forceX = true`
  • Don't let the player jump while touching.left or touching.right.
  • Write your own separation method :(

THANK YOU, game.physics.arcade.forceX = true worked for me!

Share this post


Link to post
Share on other sites
Just now, Legomite said:

THANK YOU, game.physics.arcade.forceX = true worked for me!

Awesome, that's good to know for the platformer I'm working on soon... Why didn't that property ever show up, despite the several threads about this issue I've read through.

Thanks samme!

Share this post


Link to post
Share on other sites
50 minutes ago, samme said:

It's hard to know without using `game.debug.body()` (or samme/phaser-plugin-debug-arcade-physics!).

Things you can try:

  • `game.physics.arcade.forceX = true`
  • Don't let the player jump while touching.left or touching.right.
  • Write your own separation method :(

Hmm.. It fixes the problem I mentioned but now it messed up its behavior on the x axis...

The ground blocks seem to collide with the player when I'm moving to the left. It works fine when I'm moving to the right, but the player always ends up hitting the block when walking left.

You can see how it's behaving here

http://stoneminer.comyr.com/_dev/v2/

Share this post


Link to post
Share on other sites
4 minutes ago, Legomite said:

Hmm.. It fixes the problem I mentioned but now it messed up its behavior on the x axis...

The ground blocks seem to collide with the player when I'm moving to the left. It works fine when I'm moving to the right, but the player always ends up hitting the block when walking left.

You can see how it's behaving here

http://stoneminer.comyr.com/_dev/v2/

That makes sense, same issue just in the other axis, now it's realizing it's on a wall before readjusting to be above the ground...

You could combine tactics and set forceX to true only if you are currently touching left or right and set it false if you're not? Probably in your characters update loop if they should move.

Share this post


Link to post
Share on other sites
22 minutes ago, UncleAcid said:

That makes sense, same issue just in the other axis, now it's realizing it's on a wall before readjusting to be above the ground...

You could combine tactics and set forceX to true only if you are currently touching left or right and set it false if you're not? Probably in your characters update loop if they should move.

That actually works, thanks!

Share this post


Link to post
Share on other sites
9 hours ago, ldd said:

I know that this is a totally separated issue, but you are making 102 draws per frame. My 2014 Macbook Pro nearly died :( 

Screen Shot 2017-02-10 at 12.14.29 AM.png

You NEED to create a spritesheet with all your sprites, this will cut it down to max a few draw calls; take a look at TexturePacker (https://www.codeandweb.com/texturepacker) or ShoeBox (https://renderhjs.net/shoebox/).

The reason it's using so many draw calls is because every time the renderer needs to switch textures (in your case when it runs into a tile different from the one it's already using) it has to make a draw call and switch textures. Having a spritesheet gets rid of that since all sprites share the same texture, and just show a specific part of it.

Share this post


Link to post
Share on other sites

Bump. I'm back at this problem since the solution is kind of hacky. It works for now, but in the future, I want to implement NPC's, animals, etc. and changing forceX for the entire physics system might mess with how those other things interact with the world such as walking.

 

I really don't want to switch from Arcade to P2 because my game is literally boxes, and slopes (I got a plugin for that) and P2 is incredibly overkill. Arcade is perfect besides the lack of friction, I need the game to run on mobile (currently 50 fps on my iPad Air) and it has a ton of physics bodies (every block has one). 

 

I can't make the player stop movement when the bodies are touching because the collision is only called when they're forced unto each other. It'll just stop the player for a millisecond and let it push back into the wall... Maybe increasing iteration count will help? I don't know how to do that in arcade. In P2 you can do game.physics.p2.world.solver.iterations

 

Can anybody help??

Share this post


Link to post
Share on other sites
9 hours ago, samme said:

Can you use a tilemap instead?

Otherwise you can modify body.checkCollision on each block (false on the interior edges).

I can't use a tile map. The entire world has to be dynamic. Every block has to be editable :(

Share this post


Link to post
Share on other sites
On 2/9/2017 at 9:18 PM, ldd said:

I know that this is a totally separated issue, but you are making 102 draws per frame. My 2014 Macbook Pro nearly died :( 

Screen Shot 2017-02-10 at 12.14.29 AM.png

Can you specify the model of your MacBook and specs? My 2013 MacBook Pro runs the game at 60 fps

Screen Shot 2017-07-21 at 12.18.47 PM.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.