• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Antonc13 · Jan 15 at 10:26 PM · script.bulletgun

Circular Bullet Spread for Shotgun / Bloom

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<PlayerBulletCollide>().damage = damage;

         Rigidbody rb = firedBullet.GetComponent<Rigidbody>();
         rb.AddRelativeForce(cam.forward* bulletSpeed);
     }
 }

 void EquipSound()
 {
     GameObject equipAudio = Instantiate(equipSound, transform.position, Quaternion.identity);
     equipAudio.transform.parent = GameObject.FindGameObjectWithTag("SoundHolder").transform;
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jan 16 at 03:16 AM

You're looking for my GetPointOnUnitSpereCap method. Note: Use the second one.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Antonc13 · Jan 16 at 08:25 PM 0
Share

Thank you very much! I'll give it a look.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

138 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation script 1 Answer

Shooting multiple bullets 2 Answers

gun problems 1 Answer

Help on a pick up/reload script 3 Answers

Gun Script 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges