I have a 2D game and I'm working on head rotation with my newbie coding skills. My Player has child sprite object called DefaultPistol (which is the whole arm and pistol attached to it) and it has a Weapon script. The arm turns 360 (centered from the shoulder) in the scene.
What I need is for my player turn his Head wherever arm turns (the Head is also another child sprite object attached to Player like DefaultPistol) but not like rotating the head, I just simply want to mirror the head to face left or right.
I tried setting the head's x scale to 1 or -1, but it didn't work and I couldn't find what is the problem. (I also checked the inspector if I didn't attach anything, but everything is in order as far as I can see)
Here is my Weapon. You can see where I tried to implement this in Flip. How can I fix this?
public class Weapon : MonoBehaviour { public GameObject projectile; public Transform shotPoint; public float timeBetweenShots; private Animator cameraAnim; private float shotTime; private bool facingRight; public GameObject head; private void Start() { cameraAnim = Camera.main.GetComponent<Animator>(); } private void Update() { //this code paragraph here is calculating the shotPoint player rotation Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(angle + 90, Vector3.forward); transform.rotation = rotation; if (Input.GetMouseButton(0)) { if (Time.time >= shotTime) { Instantiate(projectile, shotPoint.position, transform.rotation); cameraAnim.SetTrigger("shake"); shotTime = Time.time + timeBetweenShots; } } } private void Flip(float horizontal) { if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight) { facingRight = !facingRight; Vector3 theScale = transform.localScale; head.transform.localScale = new Vector3(); theScale.x *= -1; transform.localScale = theScale; } } } 
Flipmethod anywhere. It also seems to turn the localScale of the head to anew Vecotr3(), which would be a0:0:0vector, which would make the head disappear. It then mirrors the scale of the object the script is on, not the head. \$\endgroup\$