Estoy trabajando en un juego de matar zombis en 2D, pero hubo un error al girar el arma en mi código, cuando giro el arma, sale mal. ¿Me puedes ayudar?
Vídeo: https://youtu.be/8kUgXkEZc2M
Aquí está el código:
[SerializeField] Transform _arm; float _offset = -90; Vector3 _startingSize; Vector3 _armStartingSize; public GameObject Bullet; public float BulletSpeed; public Transform ShootPoint; #region Start // Start is called before the first frame update void Start() { _startingSize = transform.localScale; _armStartingSize = _arm.localScale; } #endregion // Update is called once per frame void Update() { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 perendicular = _arm.position - mousePos; Quaternion val = Quaternion.LookRotation(Vector3.forward, perendicular); val *= Quaternion.Euler(0, 0, _offset); _arm.rotation = val; if(transform.position.x - mousePos.x < -0.1) { transform.localScale = _startingSize; _arm.localScale = _armStartingSize; } else if(transform.position.x - mousePos.x > 0.1) { transform.localScale = new Vector3(-_startingSize.x, _startingSize.y, _startingSize.z); _arm.localScale = new Vector3(-_armStartingSize.x, -_armStartingSize.y, _armStartingSize.z); } if (Input.GetMouseButtonDown(0)) { shoot(); } } void shoot() { cineShake.Instance.ShakeCamera(5f, .1f); GameObject BulletIns = Instantiate(Bullet, ShootPoint.position, ShootPoint.rotation); BulletIns.GetComponent<Rigidbody2D>().AddForce(BulletIns.transform.right * BulletSpeed); }