# 2D Bullet hell, multi bullet spread problem

Hello there

I’ve got the a problem regarding a ranged weapon controller I’m currently implementing for a 2D bullet hell / rogue like game.

Heres a picture of the problem:

As you can see, the bullets aren’t spreading out of my fire point correctly. My target is to shoot multiple projectiles according to the “Number Of Shots” within an angle between “AttackPointOfStaff.localRotation.z - (SpreadAngleDegree/2)” and “AttackPointOfStaff.localRotation.z + (SpreadAngleDegree/2)”.

I’ve used the following code attempt to achieve this behavior:

``````    /// <summary>
/// Process a single attack
/// </summary>
public override void SingleAttack()
{
if (NumberOfShots == 1)
{
Instantiate(Projectile, AttackPoint.position, AttackPoint.rotation);
}
else
{
var angleFrom = AttackPoint.localRotation.z - (SpreadAngleDegree / 2);
var angleTo = AttackPoint.localRotation.z + (SpreadAngleDegree / 2);
var angleSteps = (angleTo - angleFrom) / NumberOfShots;

for (var i = 0; i < NumberOfShots; i++)
{
var rotation = Quaternion.Euler(AttackPoint.rotation.x, AttackPoint.rotation.y, angleFrom + i * angleSteps).eulerAngles;
var bullet = Instantiate(Projectile, AttackPoint.position, AttackPoint.rotation);
bullet.transform.Rotate(rotation, Space.Self);
}
}
AttackCounter = AttackDelay;
}
``````

I’m now looking for the problem since hours and I just don’t find it. Can anybody help out?

Best regards

I still did not find a solution, really nobody got an idea?

Ended up with the following code, which is now a little more bugfree when it comes to movement and aiming but still, the bullets arent spreading correctly.

``````    /// <summary>
/// Process a single attack
/// </summary>
public override void SingleAttack()
{
if (!CanAttack)
{
return;
}
if (NumberOfShots == 1)
{
Instantiate(Projectile, AttackPoint.position, AttackPoint.rotation);
}
else
{
var angleFrom = AttackPoint.rotation.z - (SpreadAngleDegree / 2);
var angleTo = AttackPoint.rotation.z + (SpreadAngleDegree / 2);
var angleSteps = (angleTo - angleFrom) / NumberOfShots;

for (var i = 0; i < NumberOfShots; i++)
{
var rotation = Quaternion.Euler(0f, 0f, angleFrom + i * angleSteps) * AttackPoint.rotation;
Instantiate(Projectile, AttackPoint.position, rotation);
}
}
AttackCounter = AttackDelay;
}
``````

“little more bugfree when it comes to movement and aiming but still, the bullets arent spreading correctly.”

Well that doesn’t explain much… What exactly doesn’t work, how is the pattern wrong?

Too much hassle to start guessing, and you could provide an example that can be tested as is, if you want someone to help you.

IMHO - don’t rely on euler angles, those might not be reliable… use quaternions instead which is the actual value.

You could use start rotation and end rotation, then (Quaternion)Lerp between those instead.