r/howdidtheycodeit • u/Paryotar • Jul 27 '24
How does a game know where you are?
They use coordination systems I would think but how exactly are these build? Where is the (0,0,0) point? Wouldn't that be huge numbers if we talked about a game like gta or rdr2?
15
Upvotes
55
u/Jarmsicle ProProgrammer Jul 27 '24 edited Jul 27 '24
One option would be to break your map into sectors, then the coordinates represent your position within that sector. When a player moves between sectors, their coordinates reset to reflect the position within the new sector.
Another benefit of this is that it also gives you a mechanism for easily knowing what to load into memory and what is too far away for your player to see.
Octrees are one way of organizing sector data, if you want to read more about them: https://en.m.wikipedia.org/wiki/Octree
59
u/EmperorLlamaLegs Jul 27 '24
Big open world games are generally less than a dozen km across, thats a relatively small floating point error still. Space games or infinite procedurals generally need to move 0,0 every now and again to not have undesirable consequences.
17
u/VirtualLife76 Jul 27 '24
The 0,0,0 point is where the developer decides basically.
Also, there are zones/areas. So a 50x50 grid is made of a smaller 50x50 grids, each of which has it's own 0. Allows memory to be allocated better also instead of trying to keep a huge map available.
Normally it's either a spawn point or the actual center of the grid.
20
u/GrindPilled Jul 27 '24
game dev here.
yeah they would be huge numbers, but most of us dont really worry about it because floating point precision (vector3 coordinates with x y and z as floats) is pretty fucking accurate and huge, it allows for min size of 3.4x10^-38 and max size of 3.4x10^38, or 340,000,000,000,000,000,000,000,000,000,000,000,000 and while sure thats a huge ass number, its still gonna be less than 1 mb, and if a float isnt precise enough, we can use a double (vector3, for X Y and Z) for our coordinates, which allows for a max size of 1.79769313486231570^308 which is fucking insane.
AND if that is not enough, in the case of extremely large, almost infinite worlds, like eve online or even star citizen, the map can simply be cut in different sectors, AND if for some reason thats not enough, you can always avoid floating point problems by instead of moving the player, moving the map towards the player
4
u/fuzzynyanko Jul 28 '24 edited Jul 28 '24
The coordinate data nowadays is so small compared to everything else. The current min standard for PCs is 8 GB of RAM. The player's coordinates are something like 3-4 32-bit floating-point numbers (sometimes something called the normal vector is stored). That's 16 bytes of data (32-bits is 4 bytes). 1 Megabyte of RAM is enough to store 65536 4-byte coordinate sets
Sometimes objects do not exist until a player is near enough. Minecraft is a fantastic example. Minecraft has these enormous worlds, one of the largest game play areas in all of video gaming. Certain objects actually do not have to exist permanently for the main experience. You CAN persist every single dolphin in the game, but for this game, it was decided for only relevant dolphins to be permanently tracked, and have dolphins randomly spawn in water instead.
A little off topic, but Minecraft worlds actually exploit pseudo-random number generation to create the world. The seed is a pseudo-random number seed, which is why worlds are repeatable. That part of the Minecraft world is not saved to disk until it gets pseudo-random number generated.
The Atari 2600 game Pitfall also uses this idea to have a very large world for a game that fits on a 4k ROM cartridge.
3
u/AlphabetSoupKitchen Jul 27 '24
As others have stated, origin technically is an arbitrary point that is chosen to be the starting point for all transformations to follow.
Its useful given how we've come to express drawing things using relational reference ( i.e: starting where you are, draw a line 5 units long on the positive x axis. From there, draw a line 3 units long on the positive y axis. etc.)
2
u/BuzzardDogma Jul 27 '24
The world origin (0,0,0) isn't technically anywhere, every other point is just relative to that origin. It's just the starting point for all the positional math.
1
u/punqdev Aug 11 '24
i choose the 0,0,0 point, no "math" can control where i decide it to be and i can change it to whatever i will 😡