- Home /
What is the maximum value Unity can handles before warning ?
Hello,
I'm developping an infinite exploration runner game (with several lanes and the possibility of move right / left while running) and I had a performance issue with the first version of the prototype : I was moving the environment and not the character and its camera, so it was laggy because of all the objects which were moving.
As I gonna make the character and its camera moving, until which value can I consider letting my character running forward before having to set it back to its initial position ?
My character is currently running at 15 units per second (54km/h), so 10 000 will be reached in a few minutes.
Thanks in advance !
it's "around 1000" units, but google for 100s of questions on this
note that normally you very simply "keep moving everything back to the center of your stage", that is how all runners are done. Do that.
"so it was laggy because of all the objects which were moving."
you were just doing something wrong then. it's that simple
the way you first did it is the only way to do it.
there is absolutely no reason, whatsoever, that moving the scenery would "cause lag". there is zero, no, mathematical difference from moving the camera.
it's possible you are including far, far too much scenery, not culling, not "getting rid of it behind" -- or you could be making one of a dozen basic mistakes.
Just FYI --there are many (superb) "infinite runner kits" available on the asset store for a few dollars. that's how development is done now.
for something as trivial and common as a runner, you just do that and drop in your graphics. you'd no more program one from scratch that you would say "program a database from scratch" Hope it helps
I get your point Fattie, as we're a young $$anonymous$$m of self learners on Unity we probably did something wrong. I also totally agree with you when you say that many unity plugins on the assets store that will do that job well, but we would learn to do the main part of this by ourselves first.
We have many objects moving at the same time by a single line of code :
transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - Game$$anonymous$$anager.instance.speedBlocs * Time.deltaTime);
Our hierarchy is $$anonymous$$ovingLevelDesignBloc > ParentsOfObstacles > Obstacles, and the code is put on $$anonymous$$ovingLevelDesignBloc.
As you can see on the screenshot, it is - for us - the most costly resource.
Answer by Eno-Khaon · Jan 24, 2016 at 04:32 AM
To be precise, there's no specific "safe" range using floating point numbers, per se. Floating point numbers themselves can be seen as an integer with a decimal point you can put wherever you want.
Although this isn't directly indicative of floating point numbers and their precision, you can imagine it this way:
Let's say you have a large number, such as 1 billion and 1, so... 1,000,000,001
or 1000000001.0
. That same number is almost identical to barely over 1 or 1.000000001
in floating point notation.
What this means for you, however, is that you're still limited by the bit-count of the floating point value. If you consider the maximum 32-bit signed value of 2147483647 (2.1 billion), that means that once you exceed 100,000, you would have only 5 decimal points remaining for calculation precision. The greater the number, the lower the accuracy inherently becomes, which is especially problematic for performing physics calculations. The less granularity available for the calculations, the more destructive things will become.
That said, that is also why Unity offers a warning once a position vector reaches high values; it's only there for your own sake, to avoid running into calculation issues which can't be remedied without sizable increases in calculation cost.
With runners
YOU SI$$anonymous$$PLY $$anonymous$$EEP THE CA$$anonymous$$ERA AND PLAYER AT ZERO, AND $$anonymous$$OVE THE BAC$$anonymous$$GROUND
it's just that simple.
Actually I think that you cannot do this way in many cases, mainly because of performances. The most expensive action is the movement of all the background elements, which in my case made impossible the game playable on mobile devices even with optimized assets.
Anyway, following your answers I will move my character and find a sneaky way to put everything back at the origin of the scene without being spotted by the player.
difficult to believe, i'd guess you've made some other basic woe you know?
moving something takes almost no processing power and not et hat moving the camera is just the same!
NOTE precisely as you say, another approach is you run along a track of say 1km, and then JU$$anonymous$$P BAC$$anonymous$$ TO THE START AGAIN; so you loop over say 1km. Each method has it's own incnonveniences
Answer by hexagonius · Jan 23, 2016 at 11:22 PM
According to this post going up to 100000, it's save:
http://answers.unity3d.com/questions/377376/limit-of-unity-world-space-out-of-range.html
most people keep it down to about 10,000
BUT THAT IS TOTALLY IRRELEVANT HER$$anonymous$$
when you do a runner, you very simply keep the action "near the middle of your stage", and you move the ground "under" the player character
Couldn't be simpler - one of the most basic and well-known techniques in video game engineering
Answer by Highwalker · Jan 24, 2016 at 04:03 PM
I too am making an endless type game, and from my experimentation, there's no limit. The transform position numbers just start to look odd at some point (like when you go past the max number on a calculator). But unity handles it just fine without issue. And I do use distance calculations and the likes. So as far as I know, there's really no issue.