- Home /
Question by
Mordetherelicor · Apr 19, 2017 at 09:29 PM ·
transformienumeratorbulletsrandomspawning
Bullet Hell : Shotgun spread and locking it to one axis
I am trying to make an enemy that will rush the player, look at them and fire a spread of bullets. I have the rush part working, but the look at and Spread shot parts aren't behaving quite how I want them to. I am having trouble locking the axis of the bullets to just the one plane that they can travel on. Currently depending on where the player is, they sometimes fly off into space at weird angles.
//shoots random bursts of bullets
IEnumerator ConeAttack()
{
for (int d = 0; d < NumberOfCones; d++)
{
for (int i = 0; i < ConeBulletCount; i++)
{
Vector3 dir = -ConeSpawn.transform.forward;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
float spread = Random.Range(-10, 10);
Quaternion bulletRotation = Quaternion.Euler(new Vector3(angle + spread, angle + spread, angle + spread));
bulletRotation.x = 0;
PoolManager.instance.ResuseObject(Bullets, ConeSpawn.position, ConeSpawn.transform.rotation * bulletRotation);
yield return new WaitForSeconds(ConeShotDelayTime);
}
yield return new WaitForSeconds(1);
}
}
void LookAtPlayer()
{
if (target != null)
{
Vector3 diff = target.position - transform.position;
diff.Normalize();
float AngleX = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(-AngleX, 0f + AngleY, 0f + AngleZ);
}
}
(don't worry about the pool manager, think of it like instantiate)
Comment
Your answer
Follow this Question
Related Questions
RayCast Shooting And Errors 1 Answer
Question regarding transform.getChild() 3 Answers
Deploy object avoiding collisions 0 Answers
Ai can fire Infinite bullets? 2 Answers
Simple AI random roaming 2 Answers