Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 arashsh · May 28, 2020 at 08:04 PM · rotationshootingpoolingqueue

Bullet Rotation Issue With Pooling

Hi, I Use Pool For My Shooter Game But I Have Issue With Rotation Of Bullet When Reuse In Pool

my pool

 public GameObject GetFromPool()
      {
          if(avableobjects.Count == 0)
          GrewPool();
 
          var instance = avableobjects.Dequeue();
          instance.SetActive(true);
          return instance;
      }
 
      void GrewPool()
      {
          for (int i = 0; i < 5; i++)
          {
              var instanceToAdd = Instantiate(pooledObject);
              instanceToAdd.transform.SetParent(transform);
              AddToPool(instanceToAdd);
          }
      }
 
      public void AddToPool(GameObject instance)
      {
         instance.SetActive(false);
         avableobjects.Enqueue(instance);
      }

my bullet

 void OnTriggerEnter(Collider hit)
     {
        if(hit.gameObject.tag == "Death")
         {
             PoolManager.Instance.AddToPool(gameObject);
         }
     }

my spawn

GameObject Bullet = PoolManager.Instance.GetFromPool(); if(Bullet == null)return; Bullet.transform.position = CannonAim.transform.position; Bullet.transform.rotation = CannonAim.transform.rotation; Bullet.GetComponent().FireMe();

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
0
Best Answer

Answer by Map-Builder · May 28, 2020 at 11:39 PM

Not enough info.


"have issue with rotation" ???? which issue read what you write please


code seems fine.


I suppose you use physics and bullet still goes all the way long... so it's still spinning, maybe velocity = vector3.zero

Comment
Add comment · Show 5 · 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 arashsh · May 28, 2020 at 11:52 PM 0
Share

sorry about weak info like my english! . i use addforce for moving bullet and when in trigger i say gameObject.setactive(false) everything work perfectly but when i reuse bullet in pool rotation get messy! i try before this velocity = vector3.zero but sometimes bullet not moving. before i use queue i try list but same result

avatar image Map-Builder · May 29, 2020 at 01:39 AM 0
Share

Use velocity=0 before addforce. or better before deactivating it.

avatar image arashsh Map-Builder · May 29, 2020 at 02:28 AM 0
Share

thans man, i move velocity = Vector3.zero before force and problem solve! :)

avatar image Map-Builder · May 29, 2020 at 09:06 AM 0
Share

when you add a force, it changes velocity. If you put velocity = 0 after, it cancel or.

(info for people in need who may not understand)


Try to always wonder how functions work while using it, mainly about physics.

avatar image arashsh Map-Builder · May 29, 2020 at 09:43 AM 0
Share

yes it was a lesson for me thank you. i hate physics in unity

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

167 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Need help with Transform.LookAt 1 Answer

3D top down shooter mouse follow inaccurate. 0 Answers

Shooting problem the bullets fly in diffrent direction then player looks? 2 Answers

Shoot bullet in direction which player looks 0 Answers

Help rotating gun towards mouse position (with flipping) 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