mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 10:05:53 +00:00
Shooting and big tank fix
This commit is contained in:
parent
cc00c8eaf0
commit
0a6e89faed
26 changed files with 797 additions and 9 deletions
55
Scripts/Actors/BulletSpawner3D.cs
Normal file
55
Scripts/Actors/BulletSpawner3D.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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<Bullet3D>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue