For some reason when I shoot right everything works well, but when I shoot left the bullets move down and push me
Video:
2023-03-14 18-04-07.mp4 - Google Drive
Code:
using UnityEngine;
public class gunShoot : MonoBehaviour
{
public Transform firePointR;
public Transform firePointL;
public GameObject bulletPrefab;
public flipSprite flipSprite;
public float bulletForce = 20f;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
if (flipSprite.spriteIsFlipped)
{
GameObject bullet = Instantiate(bulletPrefab, firePointL.position, firePointL.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePointR.right * bulletForce, ForceMode2D.Impulse);
}
else
{
GameObject bullet = Instantiate(bulletPrefab, firePointR.position, firePointR.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePointR.right * bulletForce, ForceMode2D.Impulse);
}
}
}
Does anyone know how to solve this? Please let me know.