Projectile Rotation

This commit is contained in:
Marco 2025-02-13 18:25:55 +01:00
commit 56ac07367b
12 changed files with 188 additions and 27 deletions

View file

@ -23,24 +23,22 @@ public partial class BulletSpawner : Node2D
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position);
bullet.Initialize(bulletInfo);
//var bullet = BulletScene.Instantiate<Bullet>();
//bullet.Position = bulletInfo.Position;
//bullet.Owner = bulletInfo.Owner;
//bullet.Speed = speed;
float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed;
bullet.Speed = modifiedSpeed;
Vector2 baseDirection = bulletInfo.Direction == Vector2.Zero ? Vector2.Right : bulletInfo.Direction.Normalized();
float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X);
//float angle = angleOffset + (360 / count) * i;
float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset + (bulletInfo.Spread / bulletInfo.BulletCount) * i);
float offsetRadians = Mathf.DegToRad(bulletInfo.RotationOffset);
float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / (bulletInfo.BulletCount - 1); // Ensure proper spread spacing
float angle = baseAngle + offsetRadians + (spreadStep * i);
// float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset + (bulletInfo.Spread / bulletInfo.BulletCount) * i);
Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
//Vector2 bulletDirection = new Vector2(Mathf.Cos(Mathf.DegToRad(angle)), Mathf.Sin(Mathf.DegToRad(angle)));
bullet.SetDirection(bulletDirection);
//GetParent().AddChild(bullet);
}
}
@ -93,5 +91,5 @@ public class BulletInfo
public PackedScene BulletScene { get; set; }
public PackedScene DestructionParticlesScene { get; set; }
public IBulletModifier Modifier { get; set; }
public List<TimeModifier> TimeModifiers { get; set; } = new List<TimeModifier>();
public List<ModifierWrapper> TimeModifiers { get; set; } = new List<ModifierWrapper>();
}