Legomite Posted February 9, 2017 Share Posted February 9, 2017 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. rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 9, 2017 Share Posted February 9, 2017 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). Link to comment Share on other sites More sharing options...
Legomite Posted February 9, 2017 Author Share Posted February 9, 2017 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? rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 9, 2017 Share Posted February 9, 2017 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. Link to comment Share on other sites More sharing options...
samme Posted February 10, 2017 Share Posted February 10, 2017 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 `body.touching.left` or `body.touching.right`. Write your own separation method rroylance 1 Link to comment Share on other sites More sharing options...
Legomite Posted February 10, 2017 Author Share Posted February 10, 2017 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! rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 10, 2017 Share Posted February 10, 2017 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! Legomite 1 Link to comment Share on other sites More sharing options...
Legomite Posted February 10, 2017 Author Share Posted February 10, 2017 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/ rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 10, 2017 Share Posted February 10, 2017 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. Link to comment Share on other sites More sharing options...
Legomite Posted February 10, 2017 Author Share Posted February 10, 2017 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! rroylance 1 Link to comment Share on other sites More sharing options...
ldd Posted February 10, 2017 Share Posted February 10, 2017 I know that this is a totally separated issue, but you are making 102 draws per frame. My 2014 Macbook Pro nearly died rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 10, 2017 Share Posted February 10, 2017 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 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. hexus 1 Link to comment Share on other sites More sharing options...
Legomite Posted July 20, 2017 Author Share Posted July 20, 2017 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?? Link to comment Share on other sites More sharing options...
samme Posted July 20, 2017 Share Posted July 20, 2017 Can you use a tilemap instead? Otherwise you can modify body.checkCollision on each block (false on the interior edges). Link to comment Share on other sites More sharing options...
Legomite Posted July 21, 2017 Author Share Posted July 21, 2017 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 Link to comment Share on other sites More sharing options...
Legomite Posted July 21, 2017 Author Share Posted July 21, 2017 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 Can you specify the model of your MacBook and specs? My 2013 MacBook Pro runs the game at 60 fps Link to comment Share on other sites More sharing options...
samme Posted July 21, 2017 Share Posted July 21, 2017 Try the body.checkCollision method then. Link to comment Share on other sites More sharing options...
Recommended Posts