Jump to content

Drag racing fps issue


Recommended Posts

We are making drag racing game. I need to make race time stay the same if parameters(car characteristics, road length and air density) stay the same.  
So what's the problem? When fps is 60 race time is always the same. But when fps is lower than 60 race time is always bigger.
You can pay it here http://propshaft.bitballoon.com/ - program automatically shifts gear on red line.
Relevant code from update function:

now = this.game.time.now;//convert spped from km/h to m/sspeedInMS = this.speed / 3.6;//calculate drag,rolling and net forces	drag = this.dragCoef * this.frontalArea * this.airDensity * speedInMS * speedInMS / 2;rollingResistance = -this.rollingResistanceCoefficient * speedInMS;f = (this.getTorqueByRPM(rpm) * this.finalDriveRatio * this.getCurrentGearRatio()) / this.tireRadius - drag - rollingResistance;//if gear shift f=0if (this.isShiftingGear) {	if (now - this.startGearShiftTime <= this.gearChangeDelay) {		f = 0;	} else {		this.isShiftingGear = false;		this.startGearShiftTime = undefined;	}}//calculate accelerationvar a = f / this.mass * 2.2;//calculate speed	this.speed += a * (now - this.oldTime) / 1000;//calculate rpm this.rpm = this.speed * 60 * this.finalDriveRatio * this.getCurrentGearRatio() / 2 / Math.PI / 3.6 / this.tireRadius;//calculate distancethis.distanceTraveled += this.speed * (now - this.oldTime) / 1000 / 60 / 60; 
Two points:

- From one side program  timer label gets time from game.time.totalElapsedSeconds(). Program restarts game timer when countdown finishes(game.time.reset);
- From other side program increments speed  based on delta time and distance based on delta time. This is two places that are affected by fps.

So the question are:
1) What is the cause of problem? If I am right lower fps means less acuracy in calculations
2) What are the possible solutions to this(will apreciate links to material that describes your point)?   

Link to comment
Share on other sites

At a quick glance, perhaps you are not considering the delta in the acceleration?


Example - Consider a compound interest from a financial calculation.  How many times in a year the compound is calculated will effect the final interest paid.


Possible solutions:


1) Fixed frame interval for all maths (e.g. 30fps, variable playback speed per device)

2) Fixed frame interval for non-linear maths (e.g. only recalculate speed every 50ms)

3) Use sub-interval maths and normalize on the frame rate (e.g. if now - oldTime is 30ms then call the functions 30 times)

Link to comment
Share on other sites

Thank you b10b for your answer. Yes you are right, I didn't think about that as compound interest formula.  :) 
Thank you for suggestion on possible solutions:
1) I totally Inderstund.And as I have seen Phaser doesn't have mechanism to set FPS.
2) In worst case if there is 30 fps(mobile devices)- 33ms, 2 frames -66ms(Maybe other number better choice for most of cases). I think this is the best possible solution. And again thank you for advice=)
3) I think I don't understand you on this case. Eg if I have formula speed+=a*dt it means

for(int i=0;i<dt*1000;i++){speed+=a*0.001;} 

But I know that I am wrong and this doesn't make difference.

For everyone that having same issue: http://gafferongames.com/game-physics/fix-your-timestep/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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