Jump to content

Platformer player sometimes passing through platforms


huridloag
 Share

Recommended Posts

Hi,

 

I'm using Phaser (2.2.1) to make my first game, a platformer. Arcade physics to do the collision detection; Tiled to make the map. The problem I'm having is that the player occasionally passes through a platform when descending from a higher point (after jumping for example). Here are what I think are the relevant bits of code:

 

Create:

this.gravity = 2200;this.blockedLayer = this.map.createLayer('blockedLayer');this.map.setCollisionBetween(1,10000,true,'blockedLayer');this.player = this.add.sprite(200,200,'player');this.player.anchor.setTo(0.5,1);this.physics.arcade.enable(this.player);

Update:

this.game.physics.arcade.collide(this.player,this.blockedLayer);

So to repeat -- it's working most of the time, but 1 jump in 8 results in the player falling down through a platform (including through the floor on occasion). Following the advice in this post I tried playing with TILE_BIAS but it just made the player act freaky around the platforms...

 

Has anyone had this problem before? Any ideas how to fix it much appreciated.

 

 

Link to comment
Share on other sites

Observing the same problem with my first Phaser game! (a Flappy bird clone made as a B'day wish :))

 

Here the ground is a tileSprite with autoScroll on, and then there's the bird sprite. Collision is enabled in update() as:

game.physics.arcade.collide(this.bird, this.ground, this.hitGround, null, this);

Every once in a while the bird falls right through the ground. The player gravity is set to 1000.

 

The working game (and source) can be viewed here: https://eternalthinker.github.io/flappy-birthday

If you let the player fall in the beginning itself, you'll see this issue with a good probability.

 

For the purposes of this game, this isn't a blocking issue, but I do worry about more complex games in the future :)

Link to comment
Share on other sites

@eternalthinker: I couldn't reproduce your problem with falling thru the ground. Did you fix it eventually?

 

@valueerror: Great - so does P2 Physics fix the problem then? For those of you with more experience than me, is there any reason why changing to P2 physics isn't a good idea, compared to Arcade physics?

 

Thanks!

Link to comment
Share on other sites

p2 still doesn't do continuous collision detection (i guess because it's a bad idea in general when it comes to performance) but tunneling in p2 only occurs at a very very high object speed against very thin walls...

 

some say that p2 physics is heavy but it actually depends on what features of p2 you use... also some very convenient functions you know from arcade are not there like "touching.down"  but there is a (custom) replacement for everything :)

Link to comment
Share on other sites

Thanks @valueerror -- that's very useful. I guess I need to look into this more broadly, in terms of the different kinds of collision detection, the best engine to use for making a platformer, etc. If Phaser, or HTML5/JS in general, can't cope with the tunnelling issue, maybe I need to look elsewhere.

Link to comment
Share on other sites

p2 can cope with tunneling as much as every other physics engine out there... (except the ones that support CCD but they also state to only activate it if absolutely necessary because it's so bad for performance)

tunneling isn't a new problem ..  it's the logical thing that occurs when the speed is to high..  the arcade physics slipthrough is something different i guess..   i had this problem with arcade and it felt like collision was suddenly deactivated completely no matter how thick the ground was .. i slipped through..

 

here are some graphics to explain it :)

 http://www.stencyl.com/help/view/continuous-collision-detection/

Link to comment
Share on other sites

That stencyl page is very clear, thanks! It's true that the problem only occurs for me when the player's falling, and my gravity is set pretty high, but it makes for a nice snappy feel to his movements. This makes me think that even on arcade the problem *is* tunnelling, despite what you're saying about the thick ground. But I'm totally new to this, so I have no idea. I'll try p2. Grateful for the feedback.

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

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