Why is unity so bad at accuracy for something as simple as whole number coordinates.
All I want to do is make a simple block placement validator which is impossible when Unities location accuracy is almost as bad as their answer/forums community.
Additionally, here is some very odd behavior.
https://www.youtube.com/watch?v=sQdlcpmrN_U
public static void SectionPlaced(GameObject mazeTile)
{
SectionValidation[] children;
children = mazeTile.GetComponentsInChildren<SectionValidation>();
foreach (SectionValidation sectionValidation in children)
{
if (instance.placedSections.Contains(sectionValidation.gameObject.transform.position))
{
Debug.LogError("placed two sections in same spot");
}
else
{
Vector3 a = sectionValidation.gameObject.transform.position;
Vector3 b = new Vector3(Mathf.Floor(a.x), 0, Mathf.Floor(a.z));
//this is the gameobject
sectionValidation.gameObject.transform.position = b;
instance.placedSections.Add(sectionValidation.gameObject.transform.position);
Debug.Log(sectionValidation.gameObject.transform.position);
}
}
EventManager.TriggerEvent("OnPlaceTile");
}
You demonstrate no awareness for basics of computer science and that is ok. Everyone starts somewhere, everyone has his Achilles' heel; totally fine.
But please make sure your question is polite enough not to be mistaken for a rather unpleasant person. Thank you.
I could not care less. Polite questions do not get answered.
Post this 17 hours ago... and not a single response. https://answers.unity.com/questions/1846439/locations-being-stored-in-map-manager-are-inaccura.html
This got 2 response within the half hour.
That paradigm alone, is exactly why, and I say again, the unity answers/forums are garbage.
Answer by Eno-Khaon · Jul 05, 2021 at 06:18 AM
is almost as bad as their answer/forums community
First off, you're generally not liable to get assistance with your problem when you badmouth the community you're seeking help from.
Lucky for you, it happens to be an interesting (if still commonly seen) subject.
In short, floating point numbers aren't a replacement for integers. They're not really comparable to integers, in the sense that (computer) math is performed in a very different manner on them. Compounded on this, 32-bit float values will have even less precision allotted to them, that they will easily not land *exactly* on an integer value.
That is only partially related to your image examples, however.
Unity's implementation of Vectors ( Vector2/ 3/ 4), when calling ToString(), rounds the decimal places of their component floating point values to the nearest tenth (i.e. single decimal place).
For reference, Debug.Log() implicitly, automatically converts anything that isn't already into a string using any available ToString() function.
First off, the only question that I've ever had answered on here was answered 3 years after it was asked... so I could careless about the difference.
you know what works? Saying what I said, and people respond almost immediately. Don't like that? Then create a community where that isn't the most efficient tactic available.
I've been using this community space for years with little to no interactions while being "polite"... Sorry to say mate, but "you're generally not liable to get assistance with your problem when you badmouth the community you're seeking help from." is bass awkwards. That is see$$anonymous$$gly the only to get any interaction, I don't like that meta either, but it works.
Case in point....
I posted this twice.... Guess which of the two actually got any intereactions?
Spoiler alert... it wasn't the one where I was being "polite"
https://answers.unity.com/questions/1846439/locations-being-stored-in-map-manager-are-inaccura.html
At any rate, I understand the limitations in converting primitives. Is the inspector also doing this?
Even in the game world the locations are off I don't see how string conversion would be affecting vectors there.
In some cases, the inspector adapts them for human readability, but in others, it doesn't.
In most cases, a value entered manually will be maintained as best as possible to be the same as what the user typed. However, programmatic values will only frequently/see$$anonymous$$gly-arbitrarily be displayed accurately.
That's really the key element here, though. In case the human-entered value and the script-generated value don't appear to be identical (and all the more if they actually aren't), that's part of why Mathf.Approximately() exists. If the value is different by a negligible amount, then it probably is functionally the same.
While the values may not be pleasing to the eye when they aren't displayed as whole numbers (or, rather, at the degree of accuracy you're hoping for), they're generally off by something like ~0.0000001 which, for all intents and purposes, may as well be zero.
its not though.
Even being off by 0.00000001 breaks the purpose of validation. And will allow the player to overlap two tiles.
These entries are also after calling RoundToInt and still losing accuracy.
Your answer
Follow this Question
Related Questions
Rotating a cube in 3D ,Rotating a cube into specific coordinates with given input 0 Answers
Spine Look Rotation Wrong 0 Answers
Getting a 2D object to face the direction of its velocity relative to other objects in the level 0 Answers
AI targeting player in complete wrong direction 1 Answer
how to shoot on different direction while moving away 1 Answer