jellewie / Unity-Gnorts

Gnorts an RTS unity game
11 stars 7 forks source link

Building rotation should be rounded to an int #71

Closed jellewie closed 5 years ago

jellewie commented 5 years ago

(this bug was discovered while testing save/loading worlds https://pastebin.com/G5BWe9tf)

https://answers.unity.com/questions/493616/euler-angle-problem-in-if-check.html

Wooden_Wall_Spiked,-7,-2,-13,1.001791E-05,False,0,100

1.001791E-05 isn't a good angle... it should be 0

Either the convert-code I made is wrong, or we have a floating point error, we should round the stuff to the closest 90 degrees

`

else if (CodeInputManager.GetButtonDownOnce(10)) //If we want to rotate the building {

 if (CodeInputManager.GetButtonDown("Alternative"))                          //If we want to rotate the other way
     InHand.transform.rotation = Quaternion.Euler(0, InHand.transform.eulerAngles.y - 90, 0);    //Rotate it 90 degrees counter clock wise
 else
     InHand.transform.rotation = Quaternion.Euler(0, InHand.transform.eulerAngles.y + 90, 0);    //Rotate it 90 degrees clock wise
 PreviousRotation = InHand.transform.rotation;                               //Save the rotation

} `

JorisVanEijden commented 5 years ago

Getting eulerAngles from a Quaternion involves complicated floating point math which will result in slight differences. In your case 1.001791E-05 == 0.00001001791. Not going to be noticable in game, but a bit awkward for the save system.

jellewie commented 5 years ago

I will keep this open (since I think I had some that were 91 degrees. if this was indeed true, we need to divide it by 90 and then round, and then multiply again. But if this happens I will report this. else we can mark this solved within a (few) week(s)