(unity) move the world or the character
I'm making a game like this: wherein a 3D ship is flying around on a 2D plane. From the player's perspective, the ship will stay stationary in the center of the screen. The question I have is whether it's better to have to ship stay stationary and the world move around the ship? Or should I have the camera follow the ship as it moves around? Notes: assume the ship can go infinitely in any direction this is in Unity, though I'm curious if that differs from other tools like Unreal I will be culling items that are offscreen either way Obviously, having the camera follow the ship is easier from the programming side of things, but I'm wondering if there's a good reason not to do that (if the player moves far enough in one direction does it hit an internal limit that would break the game)? Thanks!
Both the points brought up by projectskillz and by twyla are important considerations. However they push in opposite directions (floating point precision means you don’t want to move the player too far from the origin, but NPC ships will be extremely hard to handle if the world is moving) so you’ll need to find a third-way compromise. For an infinite universe I would try a zones approach, where the world stays still within a zone, but when the player reaches the edges of the zone the world snaps over by the width of the zone, thus always keeping the player near the origin.
There aren’t any technical drawbacks in both implementations.
That said, simplicity is very important when designing software. For many reasons. A game – most of the time -, simulates a subset of the reality. So trying to achieve a simulation that is more natural, that works like it would work in real life, is a noble objective to pursue. Even when there are some technical disadvantages.
But in your case, attaching the camera to the ship in the Hierarchy and moving the ship is the most natural way of doing. The other way doesn’t have advantages and has the disadvantage that is just… weird.
You will have the challenge of making it be able to “go infinitely” to any direction, but this is a problem you’d have on both implementations.
In unity you can move as far as you want off the origin point.
There is no internal limit. However you will encounter a different type of limit.
The floating point precision limit.
In short floating point types have a precision limit of around 7 digits no matter the placement of the dot.
So for example you moved a character past say 1000 unity units.
You wanted to move an object from 1000.0000 to 1000.0001 you may or may not see jittering and your Gameobject may or may not be exactly in the place you expect it to.
So in general you would want to keep your gameplay as close to the origin as possible.
So if you wanted to be able to infinitely move in one direction you would absolutely need to implement a system that moves the world and loads it dynamically as you move.
This is not really just a limit of unity but of just how floating point numbers work.
You could get double the precision if you were to use the double type however, Unity represents everything internally as a floating point number as they are just faster and have a lower memory footprint on almost every modern system today.
For a detailed explanation of this check here.
Asking yourself one question should make the answer glaringly apparent:
“How many game objects need to move for either implementation?“
Under most circumstances, the ship moving through the game world requires only the player’s ship itself to move. All other objects in the game remain relatively stationary in game-world-space.
If the ship is stationary and the game world moves, now you’re introducing a whole world of mathematical nightmares in trying to calculate the movements of anything else which moves within game-world-space. NPC ships (and other PC ships, if ever making a multiplayer game), planets, space stations, etc.
Think back to the days when people thought the Earth was the center of the universe and all the wonky, lopsided mathematical formulas they had to work out to explain how other known planets varied their orbit speed throughout the year (sometimes appearing to reverse directions). Even though you’ve touched on this, you don’t seem to quite realize just how deep this rabbit hole can go!
As others have pointed out, there are some issues concerning floating-point precision if you make your levels excessively large. Just be smart with your level designs and you’ll save yourself a world of headaches.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport