#floating point preccision
1 messages · Page 1 of 1 (latest)
My solution for making a world bigger than 1000x1000 in unity is to simply do so because it has no trouble doing that since that's nowhere near the limits of floating point (which are the same in any game engine that uses floating points anyway)
you should really just share what specific issues you're having rather than false assumptions about the engine. you can't blame the engine within the 1km range, this is you having a flaw in your code.
the whole post really seems more like a complaint of "unreal better" rather than an actual question also. You need to share more rather than just asking about "a good solution for floating point precision". No one knows if your problem is even related to floating point precision at the moment. If you just want to see how others handle large maps (10 km+) there are lots of resources out there by googling "how to create a large map unity"
To give benefit of the doubt that perhaps OP has been trying to make a map larger than the actual Unity size limit
If that is the case, please explain why exactly you need to make your game map be larger than this
That's already a very large map as it is
there is no benefit of the doubt here. the standard is 1 unit is 1m. they specifically said "more than 1kmx1km" and 1km is 1000m. As digiholic said, this isn't near the limits to get issues with floating point math. Unity gives a clear indicator anyways when you actually do hit a large value, which you can see by placing an object really far out in the scene. Pretty sure it shows on the transform
1000x1000 really isnt a **very **large map either
(fwiw, a little research seems to suggest unreal does use doubles in some places, including for position)
im not even using unreal , and im not going to .. i like unity with all its flaws..
ofcs 1km by 1km is not big thats the point .. you can try it yourself go to 1km mark and try to do a raycast and display a imagin on the hit point you will see the problem.. also at 2.5km mark animations start glitching which is also not a big distance..
what is the limit ? i havnt even saw any limits . for me larg mao is beyond 100km .. ofcs can be achieved by splitting world in chunks and resting player on 0 0 0 with the chunk but i thought there might be a better solution for this
yeah it does and by default they have a good system.in place to handle enormous worlds , which seems to be a default built in mechanic , ofcs not for unity tho
🤷♂️ if you really dont want to share the issue, thats fine. No ones going to be able to efficiently help you. Most people are not going to play 20 questions to pry info out
sure though, to do what you asked, I moved an existing system that i have to 9000, 0, 9000. It raycasts against the ground and uses that to determine exactly where to place objects.
Low and behold, it works exactly as it should
again it is an issue in your setup if you're having issues at the 1km mark
At 1 km, 32-bit float should still have 0.06 millimeter precision, which is less than the 0.001 precision at 10 meters, but still enough for most use cases. At 9 km it should have 1 millimeter precision. For physics, I've avoided anything beyond 5 km ideally less than 2 km.
You can put in a number here and then press the 1 and -1 buttons to see the smallest increment possible at that range.
https://www.h-schmidt.net/FloatConverter/IEEE754.html
This feels more like misunderstanding why we use single-precision floating point and what you can do in your game to improve it to avoid these types of issues. Note I don't really do game development to the extend where this bothers me so all of this is from my experience as a programmer in general.
Everything uses single-precision floating point. You can't just tell Unity to use a double or higher for positioning because everything else also uses floating point. It generally has no issues and it is much more convenient to use floating point than everything else.
Just because Unreal does something does not mean everything else is suddenly doing it wrong, or "falling behind". That statement is ridiculous. Floating point math is not suddenly a bad approach on this topic, just because it doesn't fit your use case...
That said, you're not the first with this issue and not the last one. A simple Google search yields plenty of results that explain and fix the issue. Instead of worrying about floating point imprecision because your character strives far away from the center point, you can have the world move around the character instead. Keep the character centered, move the world around.
Alternatively, keep the game as-is, but occasionally pull the character back to the center whilst updating the game world to adjust with you. Both of these will fix your issue because the game world does not need to care about being too far away.
(doubles are also floating point btw, it kinda seems like you're suggesting otherwise here?)
do you pretend or.you did not understand what i said ? i already explained to you what the problem is but you seem to ignore it .. placing a object on a hit point is not a problem you can even do that at 100km distance..
im gona be home and ama send you a vid on whats happening at what distances and thers nothing to it a simple raycast runing in update to determine the current point and display a simple sprite on the ground.
if you want a movable world to adjust it to a character's position and when it gets reset you lose static batching no ? if we are not talking about chunk loading around the player which i want to avoid maybe
you infact never explained what your problem was. this entire conversation has been you refusing to actually show your setup and the issue so far. this is what you said
you can try it yourself go to 1km mark and try to do a raycast and display a imagin on the hit point you will see the problem
now suddenly "a hit point is not a problem"
oke i did mention it partially which is janking animations beyond 2km which qt this point is the least problem ..
another problem which gets noticeable already if your 700 units away for loc 0 is that when you run a function within update loop to determin where the raycast is hiting and displaying a sprit on the hit point it jerks like crazy at 1km mark not to mention beyond that
i
I don't think you'll get any noticeable jitter from floating point error on 700 units. You must be doing something weird to get rhat effect.
well thats what i thought as well but the function is bare bone as it gets.in as that if raycats hit . do a prefab on a hit point and update its position to whatever rayhits
The reason float is used instead of double is by design - to reduce memory consumption needlessly. Most of the game unity was targeting historically never needed such big words. So why introcude extra issues just to cater for games that the engine is not used for?
You'll need to share a video + some code and setup for use to really understand what's going on.
It could be more an issue of a ray cast for example.
well i did not invent that raycast right its unity stuff , and i will do so when im home if i dont forget
and i understand that engine wa not made for it .. but why not introduce an option to offer smth like that if users want.. maybe more bigger world games would be made
Because you can't just introduce such an option. It would require fundamental changes of the entire engine. Unreal had it this way from the very early stages of development.
well i dont know what it would require they come up with a lot of strange things and get the working so .. but i gues i need tos tick to 2d g casual games like everyone else 😄
and i gues that explains why no decent world game has ever ben made with unity
You don't have to stick to 2d games. Many 3d games work just fine in the given constraints. If they didn't, no body would use unity.
well most of unity games out there are casual phone apps or games made out of small levels .. do you know any game made in unity with a decent big world ?
anyways thats a different topic.. will share smth *useful regarding the problem when i get the chance
rust?
Rust, subnautica. There are probably many more less popular games.
If engine stops you from doing something, 90% of the time it's not the engine, but you.
And the other 10% of the time there is a walkaround.
Rust made with unity ? did t know that ...
these are things you can easily google, yeah
😄
i just looked up "games with unity" and saw quite a few large games
what is google
a search engine, you can use any other one for similar results
that was a sarcastic sentence
where was the sarcasm then lmao
so here is a code snippet that runs in update
if (Physics.Raycast(ray, out RaycastHit hit, skill.MaxCastDistance + 50f, groundLayer))
{
targetPosition = hit.point;
targetIndictor.transform.position = hit.point + hit.normal * 0.01f;
sqrDist = (transform.position - targetPosition).sqrMagnitude;
indicatorMaterial.color = sqrDist <= skill.MaxCastDistance * skill.MaxCastDistance ? validColor : invalidColor;
}```
when i go close or abow 700 it starts to jitter..
also noticed that the effect is only there when mowing .. or whne the cinemachine has a noise perlin runing on it
outer wilds has a roughly 200km world with a per-frame updated floating origin, Sons of the Forest has a 3.5km square map (no floating origin). Kerbal Space Program has a world about 10% of the solar system (chunked floating origin). Subnautica has a roughly 9km^2 map. Regardless of floating point issues. Unity is terrible for open world games that require asset streaming (purely memory issues, not float issues) unless you have a team that can rebuild most of the engine and tools.
Genshin Impact, Rust, Valheim, Subnautica, Raft, Outer Wilds, Kerbal Space Program
as i said most
"most" is a meaningless word
yeah it is so what ?
Most of all games are mobile slop
it annot be used m
use words that convey meaning if you want to convey meaning
for you it has no meaning for me it has
do you need a crash course in how communication works?
from you , probably not
If the effect happens only when moving, then it's likely not related to floating point error. It's very likely just incorrect movement logic causing jitter due to movement and rendering updated being out of sync.
doesn't matter i guess , the rest of the functions are as simple as this one . well when you have a cinemachine perlin oise active its also flawed movement logic ?:D
Possibly. It's hard to say without seeing the whole code and videos of the issue.
One common mistake people make is having some logic that is supposed to happen every frame, in a fixed update, causing a desync between the logic update and rendering, leading to jitter.
It could be related to instantiating and positioning objects, moving or rotating the camera(whether through code or cinemachine), moving and rotating the character.