- Home /
Bullet Pattern for Bullet Hell
Hi all, I'm designing a bullet hell game and already came up with some patterns. However, I'm stuck now trying to achieve a certain pattern. I'm trying to make the bullet stream accelerate into a spiral clockwise then slow down and spin counter clockwise. I manage to make it spiral clockwise but couldn't get it to change direction. Please help. Thanks.
public IEnumerator Pattern006()
{
yield return new WaitForSeconds(nextShot);
GameObject enemyShot = enemyShots[mainShot];
float stepAngle = 360.0f - (360.0f / numberOfSpirals);
if (nextShot <= countdown)
{
acceleration += rotationSpeed;
for (int i = 0; i <= numberOfSpirals - 1; i++)
{
float shotDirX = shotSpawnPoint.position.x + Mathf.Sin(((angle + stepAngle * i) * Mathf.PI) / 180f);
float shotDirY = shotSpawnPoint.position.y + Mathf.Cos(((angle + stepAngle * i) * Mathf.PI) / 180f);
Vector3 shotMoveVector = new Vector3(shotDirX, shotDirY, 0f);
Vector3 shotDir = (shotMoveVector - shotSpawnPoint.position).normalized * shotSpeed;
GameObject shot = Instantiate(
enemyShot,
shotSpawnPoint.position,
Quaternion.Euler(0.0f, 0.0f, -(angle + stepAngle * i))
);
shot.GetComponent<Rigidbody>().velocity = new Vector3(shotDir.x, shotDir.y, 0.0f);
}
angle += acceleration * Time.deltaTime;
if (acceleration >= 1000.0f)
acceleration = 1000.0f;
countdown = 0.0f;
}
}
after a certain point try making your acceleration negative, or you can make a different function for spinning the other way..
Answer by Hodoer · Dec 25, 2020 at 02:27 PM
It's ok everyone, woke up with the formula in my head. Here's the solution I came up with
public IEnumerator Pattern006()
{
yield return new WaitForSeconds(nextShot);
GameObject enemyShot = enemyShots[mainShot];
float stepAngle = 360.0f - (360.0f / numberOfSpirals);
if (nextShot <= countdown)
{
acceleration += rotationSpeed / 50.0f;
for (int i = 0; i <= numberOfSpirals - 1; i++)
{
float shotDirX = shotSpawnPoint.position.x + Mathf.Sin(((angle + stepAngle * i) * Mathf.PI) / 180f);
float shotDirY = shotSpawnPoint.position.y + Mathf.Cos(((angle + stepAngle * i) * Mathf.PI) / 180f);
Vector3 shotMoveVector = new Vector3(shotDirX, shotDirY, 0f);
Vector3 shotDir = (shotMoveVector - shotSpawnPoint.position).normalized * shotSpeed;
GameObject shot = Instantiate(
enemyShot,
shotSpawnPoint.position,
Quaternion.Euler(0.0f, 0.0f, -(angle + stepAngle * i))
);
shot.GetComponent<Rigidbody>().velocity = new Vector3(shotDir.x, shotDir.y, 0.0f);
}
angle = Mathf.Sin(acceleration) * 360.0f * spinDuration;
countdown = 0.0f;
}
}
The amount that the rotationSpeed is divided by requires some tweaking to achieve the desired rotational speed. Hope this helps anyone who is stuck with the same problem.