jcs Posted November 5, 2013 Share Posted November 5, 2013 hello all, I noticed that in my platformer game the player sprite jumps much higher than he ought to when the frame-rate drops. (This is very clear running on mobile devices). You can also see this in the "starstruck" example if you add code into update() that will cause the frame-rate to drop (such as 10000 Math.sqrts or somesuch). I believe there is an issue with the application of gravity/acceleration/drag. The frame-rate should be accounted for both in the velocity and position (or rotation) calculations, but is only accounted for in the position. In ArcadePhysics.js: this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x) - body.velocity.x) / 2; ought to be: this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x) - body.velocity.x) * this.game.time.physicsElapsed * 0.5 * 60; (and likewise for the rotation and y-axis calculations) This implements the formulae found at http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html I have made this change and my game works correctly at 60fps and at the much lower frame rates I get on mobile devices (30-45fps on average). (starstruck and all the examples seem to work as well). I have this in a forked repo on github; I can enter a pull request if the dev team would like (but it's just 3 lines so someone may want to fix it themselves). cheers, josh Mike, RestingCoder and Cameron Foale 3 Link to comment Share on other sites More sharing options...
beeglebug Posted November 5, 2013 Share Posted November 5, 2013 Nice catch. I'd just do the pull request if I were you, and copy this explanation into the description just in case. Link to comment Share on other sites More sharing options...
rich Posted November 5, 2013 Share Posted November 5, 2013 Don't worry about a PR, have already implemented this after reading your post. Thanks! Link to comment Share on other sites More sharing options...
jcs Posted November 6, 2013 Author Share Posted November 6, 2013 excellent! thank you Link to comment Share on other sites More sharing options...
Recommended Posts