Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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, 2021 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, 2021 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, 2021 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.

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

Best way to make a gun? 1 Answer

c# weapon shooting script using raycasting help 1 Answer

separate script to reload. 0 Answers

How to add Bullet Velocity 1 Answer

making bullet go travel at angle fired and limit gun rotation in Unity C# version 5.2 2D 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges