randomness in game engine?


I buit a simple car racing game using w for moving forward. and a, d for left and right turn.

I noticed that the car does not follow the same path when I start the game and hold on the w key. Each time, I saw some difference in the car’s path.

Did the game engine introduce some randomness?

My game file is attached.



Racing.blend (835 KB)

The “randomness” that you’re experiencing has to do with the physics engine. It doesn’t make that much sense, but there is a bit of unpredictability in physics simulations. You’re using Fh norms to rotate your car, and the spring force that’s generated is not something that is constant (apparently).

There is no programmed “randomness,” but rather slight differences in the state of your computer when physics are calculated. I’m not an expert in this area though, so maybe somebody who works on that part of the engine can explain it better.

But I did not even press the a, or d to rotate the car. I only pressed w for moving it forward. Does the game engine computer the friction according to some random factors?

Your car also tends to fly upward off the track. You can change the gravity and it might work better. Keep up the good work! I want to play that game!

#Edit: replying to Lakewalker…

No, it does not. But the time it takes to calculate frames can affect calculations which are time-dependent in some way. Depending on how busy your processor is, the simulation might end up doing very slightly different things.

Being time-independent is known as “determinism”, meaning the program will run the same each and every time, if given the same inputs.

Bullet is deterministic, but asTheSambassador said, Fh norms apparently isn’t.

There is indeed some non-deterministic behavior in Fh norm: the spring algorithm is based solely on velocity and does not take into account the time interval between frames. If the processor does not run exactly at 60 fps, which is always the case, the randomness in frame interval will introduce randomness in the spring movements. Besides that, if you change the frame rate of the game to 30 fps for example, the spring behavior will be totally different.
That could be fixed by taking timestamp into account. If you want, you can file this as a bug report.