• 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 pommerose94 · Oct 12, 2021 at 06:45 AM · quaterniontransform.rotationtop down shootershotgun

add quaternion value to a transform.position to create a shotgun weapon for a top down shooter2D

Hello, I want to create a shotgun for my game, that instanciates 3 bullets that all go in different rotations. The 3 bullets are instanciated but do not go in different rotations here is an exerpt from my script to analyse:

     if(isWeaponShotgun)
     {
         rotationbullet1 = Quaternion.Euler(0, 0, 20);
         Debug.Log("rotation bullet 1" + rotationbullet1);
         rotationbullet2 = Quaternion.Euler(0, 0, -20);
     }
     // new part of the code
     
         void ShootShotgun()
         {
             Debug.Log("ShtgunShooot");
             GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
             GameObject bullet1 = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation * rotationbullet1);
             GameObject bullet2 = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation * rotationbullet2);
             
             Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
             Rigidbody2D rb1 = bullet1.GetComponent<Rigidbody2D>();
             Rigidbody2D rb2 = bullet2.GetComponent<Rigidbody2D>();


             rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
             rb1.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
             rb2.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);


             gunSound.Play();
             currentAmmo--;
             
             Destroy(bullet, range);
             Destroy(bullet1, range);
             Destroy(bullet2, range);
         }

But the bullet rotation does not change ( the

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 Pangamini · Oct 12, 2021 at 08:41 AM

Your bullets travel in the direction of the impulse you applied to them, it has nothing to do with their rotation. Try rotating the impulse vector instead Edit: Since you have already rotated your bullets, you could try

 rb.AddForce(rb.transform.up * bulletForce, ForceMode2D.Impulse);
 rb1.AddForce(rb1.transform.up * bulletForce, ForceMode2D.Impulse);
 rb2.AddForce(rb2.transform.up * bulletForce, ForceMode2D.Impulse);
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 pommerose94 · Oct 12, 2021 at 05:46 PM 0
Share

thank you soo much, it worked perfectly well! had some difficulties understanding quaternion and stuff like that! but this simple answer solved my problem. I gave you 2 reward points, hope you like it ;)

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

130 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

Related Questions

Store object's starting position and rotation and have it return there. 2 Answers

Calculate sum over all movements and rotations of object 1 Answer

Quaternion.LookRotation() doesn't look down 2 Answers

How can I align axis with quaternion.fromToRotation? 1 Answer

Why assigned Quaternion is creating wrong values in its Transform component 0 Answers


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