Movement speed vary on different machines

Started by
13 comments, last by Nicholas Kong 10 years, 11 months ago

Interesting. Perhaps the current milliseconds returned from the System class might vary? This part is still a mystery on why it's movement vary from one computer to another.

Advertisement

Interesting. Perhaps the current milliseconds returned from the System class might vary? This part is still a mystery on why it's movement vary from one computer to another.

Keep in mind that unless you use interpolation the visual of movement may vary wildly between computers. For example even if you use a delta to move 10 meters in your game every second, one machine may loop 120 times a second, thus incrementing your visible position slightly each frame, the other may loop 40 times a second and although you will reach the same position, the movement will appear completely different.

Then again I'm not sure what you mean about the movement varying, is it just a visual difference or is it actually moving farther? If you multiply your movement by time it should be consistant between systems.

Also, you're citing the only difference as that the desktop is 64 bit while the laptop is 32, but it sounds to me like they probably vary a lot in performance and hardware as well.

I'm not sure why nobody mentioned the right way to handle delta time.

Try this. It should independent of FPS, and computer's speed.



long startTime = System.nanoTime();
...
public void update(long milliseconds) {

// calculate delta time
long time = System.nanoTime();
float deltaTime = (time - startTime)/1000000000.f;
startTime = time;

// Handle all of the ship logic
 
// Update player position base on velocity

 
position = position.add(velocity.multiply(deltaTime));
 

 
// movement code
 
if(direction.equals("left"))
{
position.setX(position.getX() - speed*deltaTime ); // for example if speed = 100, then it will move 100 pixels per second.
}
else if(direction.equals("right"))
{
 
position.setX(position.getX() + speed*deltaTime );
}
}

That method isn't necessarily the "right" way as it actually makes the speed of the system affect the result of the simulation rather than the speed at which the simulation runs. The Fix your timestep link posted by Matias describes a more robust way to handle updates and is worth reading. (variable timesteps work great for some games but once you start mixing in more advanced physics it can give you some rather "interesting" results)

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Interesting. Perhaps the current milliseconds returned from the System class might vary? This part is still a mystery on why it's movement vary from one computer to another.

Oh so you think it's speed changed because they have different bus width, by that I mean that one computer has 32-bit OS and other 64-bit? Answer is noooo.
The only thing that is responsible to that speed change is by ONLY how powerful your computer is, it can be 32-bit can go faster than 64-bit if it has better GPU and CPU.
Just think about it, if your game runs at 800FPS on desktop, and at 400FPS on laptop, then if in your code, on every frame you increase some kind of variable by 1, that means that every second that variable will be increased by 800 on desktop, and by 400 for laptop, and if that variable is position, then that means that your player or something will move 2 times faster on desktop than laptop.
Also the algorithm I just gave you not only fixes the speed issue on different systems, but it also makes game run smoother, because all other background processes might affect your computers performance, and so one second your player might move 400 pixels, and other second player might move 350 pixels. That algorithm just fixes the performance issue, and it is used widely across in game development.
I hope it is getting clearer now.
“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh

So it depends on CPU and GPU. I understand now.

This topic is closed to new replies.

Advertisement