Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Circular Bullet Spread for Shotgun / Bloom

$
0
0
Hello All, I am currently trying to make a shotgun script for my game. I want to add a bullet spread to each bullet. I want to bullet spread to be in a circle though not a square. The Shoot function is being called by an Animation event for those who are wondering. Anybody know how I can aproach / code this? [Header("Objects")] public GameObject bullet; public Transform barrel; public Transform cam; [Header("General")] public float bulletSpeed = 1000; public float bulletSpread = 1; public int pellets; public int damage; [Header("Audio")] public GameObject equipSound; [Header("Animation")] public Animator anim; void OnEnable() { EquipSound(); } void Start() { EquipSound(); } void Update() { if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Equip")) { Animations(); } } void Animations() { if (Input.GetButton("Fire1")) { anim.SetBool("isShooting", true); } else { anim.SetBool("isShooting", false); } if (Input.GetButton("Fire2")) { anim.SetBool("isAiming", true); } else { anim.SetBool("isAiming", false); } } void Shoot() { for (int i = 0; i < pellets; i++) { GameObject firedBullet = Instantiate(bullet, barrel.position, Quaternion.Euler(0, 0, 0)); firedBullet.transform.parent = GameObject.FindGameObjectWithTag("PlayerBulletHolder").transform; firedBullet.GetComponent().damage = damage; Rigidbody rb = firedBullet.GetComponent(); rb.AddRelativeForce(cam.forward* bulletSpeed); } } void EquipSound() { GameObject equipAudio = Instantiate(equipSound, transform.position, Quaternion.identity); equipAudio.transform.parent = GameObject.FindGameObjectWithTag("SoundHolder").transform; }

Viewing all articles
Browse latest Browse all 592

Trending Articles