[Call of Duty noise] shotgun unlocked
This commit is contained in:
13
Scripts/ShotgunBullet.cs
Normal file
13
Scripts/ShotgunBullet.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,4 @@ public partial class TestBullet : Projectile
|
||||
{
|
||||
Translate(new Vector3(0, 0, Speed * -(float)delta));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user