I implemented the sword rotation a little differently. I tried to take the mouse position relative to the player instead of the center of the screen. This way as the player moves around the sword rotation will follow the mouse’s position relative to the player. This also seemed to help with the flipping as it created negative angles for the left side of screen.
private void MouseFollowWithOffset()
{
float angle = Mathf.Atan2(Input.mousePosition.y -
Camera.main.WorldToScreenPoint(playerController.transform.position).y,
Input.mousePosition.x -
Camera.main.WorldToScreenPoint(playerController.transform.position).x) * Mathf.Rad2Deg;
if(Input.mousePosition.x >
Camera.main.WorldToScreenPoint(playerController.transform.position).x)
{
activeWeapon.transform.rotation = Quaternion.Euler(0, 0, angle);
weaponCollider.transform.rotation = Quaternion.Euler(0, 0, angle);
}
else
{
activeWeapon.transform.rotation = Quaternion.Euler(0, 0, angle);
weaponCollider.transform.rotation = Quaternion.Euler(0, 0, angle);
}
}