Jump to content

Ability to fall through walls at low FPS - arcade physics


ashes999
 Share

Recommended Posts

I started using this excellent Phaser tutorial: http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game

 

I skipped to part nine. I added a method called createStar(), which I call twice when a user collects a star:

 

function collectStar (player, star) {        // Removes the star from the screen    star.kill();    createStar(Math.random() * (800 - 96))    createStar(Math.random() * (800 - 96))    //  Add and update the score    score += 10;    scoreText.text = 'Score: ' + score;}function createStar(x) {  //  Create a star inside of the 'stars' group  var star = stars.create(x + (Math.random() * 60) - 30, 0, 'star');  //  Let gravity do its thing  star.body.gravity.y = 100;  //  This just gives each star a slightly random bounce value  star.body.bounce.y = 0.4 + Math.random() * 0.2;    if (starsText !== 'undefined'&& starsText != null && stars != 'undefined' && stars != null) {    starsText.text = 'Stars: ' + stars.total;  }}

(Note: in the initial for-loop, pass in i * 70 to reproduce the original behaviour.)

 

As you can imagine, eventually, you can get to lots and lots of stars. On my Ubuntu VM, I clock in around 800 stars before the FPS drops to 30.

 

Some observations:

- The game stutters when I move into a place where I collect a ton of stars -- looks like the collision handling

- Once I reach around 10-15 FPS (first noticed at 13 FPS), I sometimes try to jump onto the bottom platform but fall through instead.

 

Is this a bug? 

 

In other frameworks, when you control the update call, you can usually call it with a small value if a large amount of time elapses, eg. if one second passed since the last call, you advance game time by calling update(100ms) ten times.  This is supposed to be the fix for high-speed (or low-FPS) physics.

 

Full PasteBin is here: http://pastebin.com/TpjQrxAQ

 

Link to comment
Share on other sites

Basically, with the way physics are implemented in Arcade that is gonna happen sometimes. The only 100% way to prevent this is to implement continuous collision detection (ccd) which is I believe out of scope for what arcade physics is trying to accomplish.

Link to comment
Share on other sites

If that's true, is there a different physics engine that solves this problem?

 

Not being able to guarantee stable physics at low framerates is pretty problematic, what with the large range of available phone hardware (not to mention PC/web).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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