[solved] Is running into the infinite bad?

J

JoltJab

Guest
So I'm making an endless runner style game and I wanted to know if there's any negatives to having the character running forward forever (or until game over)? With a custom camera you can go outside the room size while still following the player. As a noob I find it easier to move the player forward instead of treadmilling the world behind her.

I did a test to see if there was any problems. I had the character fall forward (around 10 pixels per frame I think) for about an hour to see if it slowed anything down. At the same time, I had boxes that would spawn and move in random directions. After being a certain distance away from the player they would delete themselves. It was the quickest/dirtiest way to simulate there being a bunch of things existing like an actual game would. I also pushed it close to it's limits with the FPS.




--Character on left spawning a brazillion boxes on her face--

After running this for an hour (and still currently running) it doesn't look like there's any negatives to having the character run forward instead of moving the world treadmill style (but I'm a noob and could be missing something). The frame rate is still around the same point as where it started, and the memory used isn't increasing as time goes on. So, is there any reason this CAN'T work? I just felt like there could be something wrong with doing this.
 

Alice

Darts addict
Forum Staff
Moderator
Generally, with the speed of about 10px per frame and, say, 1000 FPS framerate (this game must be very optimised :3) it would take circa 11 days before the character would reach the position of billion (10^9). It would take another 11 days to reach something close to largest 32-bit signed integer, and then it would take something like millions times that to reach the highest precise double-precision floating point precision. So, unless you plan to run your game for magnitudes longer than millenia or don't clean up the mess left behind (which you do), there should be no adverse effects, I think. Then again, you said you are making an endless runner... *whistling*

(generally, real numbers in GM seem to be double-precision floating point numbers, as I found out by experimenting some other time)
 

GMWolf

aka fel666
You should be fine. Mostly...
Its possible that as you go on, the precision of the player position (and, any other objects position, actually) will decrease. (To understand why, look up floating point numbers).
This means that as you go further and further, the character may seem to clip through items, or collide unexpectedly.

This should only happen when you reach incredible distances though, and I don't think you would reach them, realistically speaking.
I am not sure how large a number must be before the lack of precision is made apparent, but I know some games (KSP, star citizen) run into this problem themselves.

For now I would recommend you stick to what you know. As far as I'm aware you should have no problem using this technique. But its good to keep its limitations in mind in case you encounter weird behavior later on.
 

GMWolf

aka fel666
Even then, the position will eventually loop back to zero and start over. The game won't ever just go bang.

Yes, it will run for the lifetime of your PC.
I don't think float numbers do that... Do they? (Now I'm gonna have to actually yes that...).
I thought the precision just went down until the number you added was smaller than the precision...
 
A

Annoyed Grunt

Guest
Don't floats eventually go into +inf or -inf? They don't overflow.
 
J

JoltJab

Guest
Alice: wow, thanks for doing out all the math! And though I don't know what a double-precision floating point number is, it sounds like I'm good to go!

Fel666:So I looked up floating point numbers, I understand your worry. If I notice any strange problems, I could probably figure out a way to seamlessly move everything back to 0,0.

Lonewolff: Ok that's good to know thanks! Also, though the calculations will include float values, the final output will be whole numbers. I don't know if that makes them integers or not, but they will be "floor"ed or "round"ed or something like that.

Annoyed Grunt: what is +inf or -inf?


I can see how there could be problems (though probably not with what I'm doing) about going too far. If I come across the errors you guys talked about I'll know what it is now and can act accordingly.Thanks guys for all your comments!
 
Top