I have an empty object called “Player”, which has several child objects. When turning left or right I rotate the Player object but when I make the player look towards the mouse, I rotate several child objects (aka TopBody). Problem is, when facing left the rotation is upside down. It works perfectly when facing right tho.
foreach(GameObject GO in TopBody)
{
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
//rot_z 0 = right, 90 = up, 180 = left
if (rot_z < 180 && rot_z > 90) //left-up //this is the part that doesn't work so well
{
if (!isFacingLeft)
{
RotateLeft();
}
GO.transform.rotation = Quaternion.Euler(0f, 0f, rot_z);
}
if(rot_z < 90 && rot_z > 0) //right-up //this part works perfectly
{
if (isFacingLeft) RotateRight();
GO.transform.rotation = Quaternion.Euler(0f, 0f, rot_z);
}
}
I’ve tried changing rotation values but so far nothing has worked.
I also tried this:
/*Vector3 temp = GO.transform.position;
temp.y += 180;
temp.z = rot_z;
GO.transform.eulerAngles = temp;*/
This part turns the object right way, but the aim is mirrored (when aiming high left, the rotation is low left and aiming low left rotation is high left, if that makes any sense."
Any help is appreciated!