[Call of Duty noise] shotgun unlocked

This commit is contained in:
2023-09-02 02:06:16 -07:00
parent de037da23b
commit 8d5ca74330
8 changed files with 109 additions and 14 deletions

13
Scripts/ShotgunBullet.cs Normal file
View File

@@ -0,0 +1,13 @@
using Godot;
using System.Linq;
public partial class ShotgunBullet : Projectile
{
public override void _PhysicsProcess(double delta)
{
var pellets = GetChildren().OfType<RigidBody3D>();
foreach (var pellet in pellets)
pellet.Translate(new Vector3(pellet.Rotation.Y, 0, Speed * -(float)delta));
}
}

View File

@@ -6,5 +6,4 @@ public partial class TestBullet : Projectile
{
Translate(new Vector3(0, 0, Speed * -(float)delta));
}
}

View File

@@ -5,12 +5,16 @@ public partial class TestCharacter : CharacterBody3D
[Export]
private float _speed = 5.0f;
[Export]
private PackedScene _attackPattern;
private PackedScene _fireProjectile;
[Export]
private PackedScene _altFireProjectile;
public override void _PhysicsProcess(double delta)
{
if (Input.IsActionJustPressed("p1_fire"))
Fire();
if (Input.IsActionJustPressed("p1_altfire"))
AltFire();
Velocity = CalculateCharacterMovement();
MoveAndSlide();
@@ -37,8 +41,15 @@ public partial class TestCharacter : CharacterBody3D
private async void Fire()
{
GD.Print("Shoot");
var projectile = _attackPattern.Instantiate<Projectile>();
var projectile = _fireProjectile.Instantiate<Projectile>();
projectile.Position = Position + new Vector3(0f, 0f, -0.2f);
GetParent().AddChild(projectile);
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
}
private async void AltFire()
{
var projectile = _altFireProjectile.Instantiate<Projectile>();
projectile.Position = Position + new Vector3(0f, 0f, -0.2f);
GetParent().AddChild(projectile);
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");