# [2D] Rotations become tighter the further left they are

What I’m trying to do is instantiate multiple projectiles based on one rotation, and slightly adjust the rotations of the projectiles through iteration to create a ‘cone attack’ effect. However, it only works well when the target is to the right of the origin/attacking unit. The rotations of the projectiles become tighter and tighter the further left the target is, until they’re all overlapping when the target is directly left of the origin. Any help or insight would be greatly appreciated.

``````    for (var i = 0; i <= NumberOfPulses; i++)
{
var didCenter = false;
for (var n = 1; n <= BulletsPerPulse; n++)
{
if (n == 0) continue;
_playerPos = _playerTransform.position;
_myPos = _myTransform.position;

// rotation toward player -->
var diff = _playerPos - _myPos;
diff.Normalize();
var newRotation = Quaternion.Euler(0f, 0f, rotZ);
var newRot1 = newRotation;
var newRot2 = newRotation;
// <--

bullet1 = Instantiate(Projectile, _myPos, newRot1) as GameObject;
bullet2 = Instantiate(Projectile, _myPos, newRot2) as GameObject;
if (!didCenter)
{
bullet3 = Instantiate(Projectile, _myPos, newRotation) as GameObject;
if (bullet3)
{
didCenter = true;
}
}

if (!bullet1 || !bullet2) continue;

bullet1.transform.rotation = newRot1;
bullet2.transform.rotation = newRot2;

}
yield return new WaitForSeconds(TimeBetweenPulses);
}
}
``````

You appear to be falling for a classic newbie trap: you believe that someRotation.z is equivalent to changing the Z value in the inspector. This should really be a FAQ on this forum… it comes up a lot.

Quaternions, despite the appearance in the Inspector, are not three numbers - those are the Euler angles of the rotation. They actually contain four 0-to-1 numbers, which bear little to no superficial relation to the Euler angle numbers. In general, if you don’t have a full understanding of Quaternions, you’ll never want to modify a rotation’s values directly - use the many helper functions provided by the class, instead.

For your situation, I’d probably recommend using Quaternion.AngleAxis to change the rotations of your shot.

Thanks a ton, StarManta. I’ll look into that and post back with my solution if I find one.

And yeah… Quaternions have proven to stump me a number of times over the years with Unity. I should just buckle down and learn about them once and for all…

As promised, my solution:

``````{
if (n == 0) continue;
_playerPos = _playerTransform.position;
_myPos = _myTransform.position;

var diff = _playerPos - _myPos;

var newRotation = Quaternion.LookRotation(diff, -Vector3.forward);
newRotation.x = 0f;
newRotation.y = 0f;

_bullet1 = Instantiate(Projectile, _myPos, newRotation * Quaternion.AngleAxis(newRotation.z + n * BulletSpreadVariance, Vector3.forward)) as GameObject;
_bullet2 = Instantiate(Projectile, _myPos, newRotation * Quaternion.AngleAxis(newRotation.z - n * BulletSpreadVariance, Vector3.forward)) as GameObject;
// ^^ these two lines handle all of the rotation by instantiating it with the desired rotation using angleaxis.

if (!didCenter)
{
_bullet3 = Instantiate(Projectile, _myPos, newRotation) as GameObject;
if (_bullet3)
{
didCenter = true;
}
}

if (!_bullet1 || !_bullet2) continue;