phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.25k stars 7.1k forks source link

Sprites can fall through platforms with phaser 2.2 (regression from phaser 2.0) #1490

Closed insidewhy closed 9 years ago

insidewhy commented 9 years ago

With your tutorial: http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game

If you run that with phaser 2.2.1 and jump up and down on the middle platform (about 50-100 times)... eventually the player will fall through the platform.

With phaser 2.0 you can jump up and down for hours and never fall through the platform.

This seems to affect/hamper any attempt I make at writing a 2d platformer :(

insidewhy commented 9 years ago

Also tried with the latest dev branch, same issue.

insidewhy commented 9 years ago

Increasing game.physics.arcade.OVERLAP_BIAS from it's default of 4 to 10 seems to have helped with this, but it seems like a pretty serious issue for platformers not to work with the default setting.

I tried reducing the gravity from your demo... to have really floaty physics. But even that lead to fall through.

insidewhy commented 9 years ago

Even at OVERLAP_BIAS 10 the fall-through can still occur, even though it's rarer. I'm worried there will be consequences setting it even higher. About ready to give up on phaser and try a different game engine, such a shame given how polished phaser seemed.

insidewhy commented 9 years ago

One thing I'm positive about is that if I switch to another browser window and back while the player is falling... this makes it way more likely for the character to fall through the floor.

photonstorm commented 9 years ago

When you said you tested the dev branch, did you actually rebuild Phaser before testing? using the provided grunt scripts. If not, it wouldn't have had the most recent fixes included.

insidewhy commented 9 years ago

Yep, using the dev build and typing "grunt" after every change. I've also been rebuilding phaser frequently after that as I've been trying to fix this issue myself.

I'm very familiar with how you're using the deltas and doing the collision detection now. I'm not quite sure how the player manages to fall through the platform by more than OVERLAP_BIAS though (given their own deltaY should be accounted for). Also given the fixed-step physics engine I'm not sure why creating artificial time delays by switching in and out of the browser window leads to this issue occurring more frequently (if you increase gravity you can easily reproduce that one).

I tried to write an isolated test targeting the physics engine only but couldn't reproduce the tunnelling so I think there are multiple factors.

photonstorm commented 9 years ago

Fair enough. I can jump up and down constantly on that platform with current dev without going through it, so it's not only multi-factor specific, but device/config influenced as well.

insidewhy commented 9 years ago

It takes me about 50-100 jumps to reproduce it on Chromium/Chrome Linux. I'll try firefox also.

insidewhy commented 9 years ago

I'm not sure but the fact it occurs more frequently when switching browser windows/tabs leads me to believe it might trigger more frequently under higher CPU loads.

insidewhy commented 9 years ago

Yep can reproduce it in firefox/linux also.

insidewhy commented 9 years ago

It's much harder (but not impossible) to reproduce it on my laptop which has a much better GPU (but not so good CPU).

photonstorm commented 9 years ago

Ok dev now contains the latest fix for this. Probably worth testing in normal circumstances first (i.e. not constant tab swapping, but just 'jumping'). If you need to simulate high browser load there are easier ways :)

insidewhy commented 9 years ago

Thanks for fixing this so quickly, this one really worried me given I couldn't get a single 2d platformer example to work! I hope you don't mind if I leave this issue open for another day while I do some more testing. Thanks again!

insidewhy commented 9 years ago

If you're not too busy, would you mind writing a few sentences about what the problem was and how this fixed it?

photonstorm commented 9 years ago

You can follow the relevant discussion here: https://github.com/photonstorm/phaser/pull/1493

insidewhy commented 9 years ago

Thanks!