using Cirno.Scripts.Components; using Cirno.Scripts.Controllers; using Cirno.Scripts.Weapons; using Godot; namespace Cirno.Scripts.Actors; public partial class BulletSpawner3D : Node3D { [Export] public PackedScene BulletScene; public void SpawnBullet(BulletInfo bulletInfo, Vector3 position) { var bulletScene = bulletInfo.BulletScene ?? BulletScene; Bullet3D bullet; int count = bulletInfo.BulletCount; float spreadRadians = Mathf.DegToRad(bulletInfo.Spread); float step = count > 1 ? spreadRadians / (count - 1) : 0; for (int i = 0; i < count; i++) { bullet = PoolingManager.Instance.SpawnBullet(bulletInfo.OriginalBulletResource); bullet.GlobalPosition = position; if (bulletInfo.Modifier is not null) { bulletInfo = bulletInfo.Modifier.ModifyBullet(bulletInfo, i, count); } bullet.Initialize(bulletInfo); Vector2 baseDirection = bulletInfo.Direction == Vector2.Zero ? Vector2.Right : bulletInfo.Direction.Normalized(); float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X); // Spread centered: offset from center float offsetFromCenter = (i - (count - 1) / 2.0f) * step; float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset) + offsetFromCenter; Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); bullet.SetDirection(bulletDirection); // float offsetRadians = Mathf.DegToRad(bulletInfo.RotationOffset); // float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / Mathf.Max(1, bulletInfo.BulletCount - 1); // Ensure proper spread spacing, also add 1 if 0 // float angle = baseAngle + offsetRadians + (spreadStep * i); // // // Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); // // bullet.SetDirection(bulletDirection); } } }