In the game I'm creating I have a square that rotates around a parent point, I want the square to always aim upright however (think of a rotating platform). What I've done is simply use
child.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -gameObject.transform.rotation.z)
This rotates the child object in the opposite direction so that they're always aiming in the right direction. Except it doesn't, there is some error that piles up with bigger rotations. For example at 90º the child object will be rotated -90.77 instead which is very noticeable given that the game has a grid of sorts and when objects are not aligned to it they instantly pop out.
So my question is, is there any way to avoid this error?