- Home /
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();
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
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
Use velocity=0 before addforce. or better before deactivating it.
thans man, i move velocity = Vector3.zero before force and problem solve! :)
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.
yes it was a lesson for me thank you. i hate physics in unity
Your answer
![](https://koobas.hobune.stream/wayback/20220612235520im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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