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;
}
}