- Home /
Weird offset while Instantiating GameObject
Hi,
So let's say I have this in my code:
Instantiate (exampleGameObject, new Vector3 (10, 0, 5), Quaternion.Euler(new Vector3 (0, 90, -90)));
Everything works fine, the gameobject is spawned, location is right, same about rotation, but... not enough. About 40% of objects get something weird like scale: 1, 1, 1.000001 or position: 9.999985, 0, 5 and same little problem with rotation. Axis on which this happens and everything else seems random to me, is there a way to fix it? It's really annoying to keep everything perfect in variables instead of using in-world position etc.
Also setting those values later through code doesn't seem to work aswell, percentage is smaller, but still happens.
It's either a very weird feature or maybe my PC just doesn't like even numbers.
What makes this "critical"? Difference is what one millionth, I can't really think of anything that would be affected by this. Floating point numbers aren't just fully accurate.
Answer by tanoshimi · Feb 23, 2017 at 08:25 AM
That's completely normal and expected behaviour, caused by inherent imprecision of floating-point calculations (and rhe additional imprecision of converting rotations from Euler angles to Quaternions). Simply ignore it and carry on.
Oh well, this is one real trouble for connection detection... Thanks anyway, gotta play with structs a little.
If this presents any real trouble for you, there's something wrong with your approach. Floating point imprecision is a property of mathematics - it's not any limitation of Unity.
it's just, variable stays as it is, but object can be at different position than what I pass and I don't understand the logic here
Your answer
Follow this Question
Related Questions
[solved] Get upward orientation of object and add scale value 1 Answer
Calcultate spawn position based on spawn volume's rotation 2 Answers
postion scale and rotation greyed out and not working 1 Answer
Add an offset to the position of an object in front of it 1 Answer
How to Decompose a TRS Matrix? 3 Answers