Working on a 2D Top Down Shooter, in my Shoot method im ejecting casings from the bullet from an ejectPoint (basically an empty gameobject). To make it look a little bit better i wanted to rotate the ejectpoint so they dont get ejected in a straight line and it kind of works. The problem is, it doesnt set the rotation but rather keeps adding to the rotation.
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
GameObject casing = Instantiate(casingPrefab, ejectPoint.position, Quaternion.Euler(0, 0, Random.Range(0.0f, 360.0f)));
Rigidbody2D bulletrb = bullet.GetComponent<Rigidbody2D>();
Rigidbody2D casingrb = casing.GetComponent<Rigidbody2D>();
//add rotation for spread??
float randomZ = Random.Range(10,20);
ejectPoint.transform.Rotate(0, 0, randomZ);
bulletrb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
casingrb.AddForce(ejectPoint.up * ejectForce, ForceMode2D.Impulse);
}