Ok, so I have an editor script I am building for laying out roads in the unity editor. One of the things it does is rotate the road segments 90 degrees to the right or left. EVERY SINGLE METHOD of doing this leaves a floating-point error, resulting in the rotation of the object being 90.00001 rather than 90.
Now I understand that’s theoretically a limitation of floating-point values and all that except:
A: It is actually noticeable, you can see a pixel line where the roads don’t line up
and more importantly
B: It can be fixed by editing the rotation manually in the transform inspector
So unity IS capable of getting around the floating-point error, but only through the inspector interface. All attempts to set the value via code result in the same stupid floating point error.
I NEED to remove the floating-point error because the other option is to have our level designer manually fix the rotation for EVERY. SINGLE. ROAD.
I have tried the following:
//The obvious first attempt
transform.eulerAngles = new Vector3(0, 90, 0);
//Set the Quaterinion rotation directly
transform.rotation = new Quaternion(0, 0.7f, 0, 0.7f);
//Set the quaterninon rotation directly using values reported from debug logs after manually setting rotation to exactly 90
objs*.transform.rotation = new Quaternion(0, 0.7071068f, 0, 0.7071068f);*
//Set the Quaterinion rotation directly but add a bunch of extra zeros to try to move the decimal place out to somewhere it won’t cause problems
transform.rotation = new Quaternion(0.00000000f, 0.70000000f, 0.00000000f, 0.70000000f);
//Set based on angle axis
transform.rotation = Quaternion.AngleAxis((int)90, new Vector3(0, 1, 0));
//Set by modifying transform forward
transform.forward = new Vector3(1,0,0);
//use rotate
transform.Rotate(0, 90, 0);
What I assume is happening is that every method to set rotation ultimately goes through the same flawed code path, except for the transform inspector. So what I think MIGHT work is somehow having my script access the transform inspector rather than the transform values themselves but I am not sure if unity will even allow me to do that. So far I haven’t found a way to access the inspector UI through an editor script. Because why would you need to when your editor script could just set values directly, etc…
Any help anyone can give me would be greatly appreciated.