#floating point preccision

1 messages · Page 1 of 1 (latest)

drifting briar
#

not sure how Unity is falling way behind on this compared to unreal, but maybe someone here can share a good solution for floating point precision , more specifically on creating a game world with a scale of more than 1kmx1km.. unreal handles this by default not sure why unity does not.

hoary eagle
#

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)

limber saddle
#

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"

brittle badge
#

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

limber saddle
# brittle badge To give benefit of the doubt that perhaps OP has been trying to make a map large...

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

candid zephyr
drifting briar
drifting briar
drifting briar
limber saddle
#

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

zealous radish
#

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.

leaden arch
#

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.

candid zephyr
leaden arch
#

Double-precision floating point *

#

updated

drifting briar
# limber saddle 🤷‍♂️ if you really dont want to share the issue, thats fine. No ones going to b...

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.

drifting briar
limber saddle
drifting briar
brazen flume
drifting briar
brazen flume
#

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?

brazen flume
#

It could be more an issue of a ray cast for example.

drifting briar
#

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

brazen flume
#

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.

drifting briar
#

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

brazen flume
#

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.

drifting briar
#

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

candid zephyr
#

rust?

brazen flume
#

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.

drifting briar
candid zephyr
#

these are things you can easily google, yeah

drifting briar
#

😄

candid zephyr
#

i just looked up "games with unity" and saw quite a few large games

drifting briar
#

what is google

candid zephyr
#

a search engine, you can use any other one for similar results

drifting briar
#

that was a sarcastic sentence

candid zephyr
#

where was the sarcasm then lmao

drifting briar
#

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
sleek solstice
# drifting briar well most of unity games out there are casual phone apps or games made out of sm...

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.

hoary eagle
drifting briar
#

as i said most

sleek solstice
drifting briar
#

yeah it is so what ?

hoary eagle
#

Most of all games are mobile slop

drifting briar
#

it annot be used m

sleek solstice
#

use words that convey meaning if you want to convey meaning

drifting briar
#

for you it has no meaning for me it has

sleek solstice
#

do you need a crash course in how communication works?

drifting briar
#

from you , probably not

brazen flume
drifting briar
brazen flume
#

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.