Refactor projectiles

This commit is contained in:
2023-09-06 15:20:34 -07:00
parent d536aa2014
commit d7dd58b5df
11 changed files with 138 additions and 181 deletions

View File

@@ -1,16 +1,21 @@
using Godot;
using Godot.Collections;
using System.Linq;
public partial class Projectile : Node3D
{
[Export]
public double Cooldown { get; protected set; }
[Export]
protected float _projectileSpeed = 1f;
[Export]
public AudioStream _soundEffect;
public Character ParentCharacter;
[Export]
protected float _projectileSpeed = 1f;
private Array<Path3D> _paths;
public override void _Ready()
{
@@ -18,12 +23,19 @@ public partial class Projectile : Node3D
var sfxPlayer = GetTree().Root.GetNode<AudioStreamPlayer>("Main/SFXPlayer");
sfxPlayer.Stream = _soundEffect;
sfxPlayer.Play();
_paths = new Array<Path3D>(GetChildren().OfType<Path3D>());
}
public override void _PhysicsProcess(double delta)
{
foreach (var paths in _paths)
{
var pathFollow = paths.GetChildren().OfType<PathFollow3D>().Single();
pathFollow.Progress += Speed * (float)delta;
if (pathFollow.ProgressRatio > 0.9f)
QueueFree();
}
}
public float Speed { get; private set; }
public void OnTimeToLiveTimeout()
{
QueueFree();
}
}

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://5ce7ky4o0q2e"]
[ext_resource type="Texture2D" uid="uid://dha44dnvwhajo" path="res://Textures/Projectiles/Projectile_Capricorn.png" id="1_bvyt4"]
[ext_resource type="Script" path="res://Player/Capricorn/Attacks/CapricornLaserShot.cs" id="1_nkyy8"]
[ext_resource type="Script" path="res://Player/Base/Projectile.cs" id="1_ovnwu"]
[ext_resource type="AudioStream" uid="uid://bykwwct1not4e" path="res://Audio/SFX/capricorn laeser.wav" id="2_lofnw"]
[sub_resource type="Curve3D" id="Curve3D_bnc6v"]
@@ -16,8 +16,9 @@ height = 7.40727
radius = 0.419241
[node name="CapricornLaser" type="Node3D"]
script = ExtResource("1_nkyy8")
script = ExtResource("1_ovnwu")
Cooldown = 1.0
_projectileSpeed = 3.0
_soundEffect = ExtResource("2_lofnw")
[node name="Forward Shot" type="Path3D" parent="."]
@@ -32,7 +33,7 @@ tilt_enabled = false
[node name="Hitbox" type="RigidBody3D" parent="Forward Shot/PathFollow3D"]
transform = Transform3D(-1, 0, -0.000800046, 0, 1, 0, 0.000800046, 0, -1, 0.000400023, -1, 0.5)
collision_layer = 0
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
continuous_cd = true
@@ -62,7 +63,7 @@ tilt_enabled = false
[node name="Hitbox" type="RigidBody3D" parent="Backward Shot/PathFollow3D"]
transform = Transform3D(-1, 0, -0.000800046, 0, 1, 0, 0.000800046, 0, -1, 0.000400023, -1, 0.5)
collision_layer = 0
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
continuous_cd = true

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://cdsc35cj566q1"]
[ext_resource type="Script" path="res://Player/Capricorn/Attacks/CapricornLaserShot.cs" id="1_8lywi"]
[ext_resource type="Script" path="res://Player/Base/Projectile.cs" id="1_tbx8y"]
[ext_resource type="Texture2D" uid="uid://dha44dnvwhajo" path="res://Textures/Projectiles/Projectile_Capricorn.png" id="2_8osg4"]
[ext_resource type="AudioStream" uid="uid://bykwwct1not4e" path="res://Audio/SFX/capricorn laeser.wav" id="2_jeoco"]
@@ -17,10 +17,10 @@ radius = 0.419241
[node name="CapricornLaser" type="Node3D"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
script = ExtResource("1_8lywi")
script = ExtResource("1_tbx8y")
Cooldown = 1.0
_soundEffect = ExtResource("2_jeoco")
_projectileSpeed = 3.0
_soundEffect = ExtResource("2_jeoco")
[node name="Forward Shot" type="Path3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.25)

View File

@@ -1,35 +0,0 @@
using Godot;
using Godot.Collections;
using System.Linq;
public partial class CapricornLaserShot : Projectile
{
private Array<Path3D> _paths;
public new float Speed { get; private set; }
public override void _Ready()
{
Speed = _projectileSpeed;
var sfxPlayer = GetTree().Root.GetNode<AudioStreamPlayer>("Main/SFXPlayer");
sfxPlayer.Stream = _soundEffect;
sfxPlayer.Play();
_paths = new Array<Path3D>(GetChildren().OfType<Path3D>());
}
public override void _PhysicsProcess(double delta)
{
foreach (var paths in _paths)
{
var pathFollow = paths.GetChildren().OfType<PathFollow3D>().Single();
pathFollow.Progress += Speed * (float)delta;
if (Mathf.IsEqualApprox(pathFollow.ProgressRatio, 1.0f))
QueueFree();
}
}
private void OnBulletHitObject(Node node)
{
QueueFree();
}
}

View File

@@ -1,13 +0,0 @@
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

@@ -1,27 +1,37 @@
[gd_scene load_steps=7 format=3 uid="uid://bq40xbqibrk1y"]
[gd_scene load_steps=6 format=3 uid="uid://bq40xbqibrk1y"]
[ext_resource type="Script" path="res://Player/Pisces/Attacks/ShotgunBullet.cs" id="1_0khuu"]
[ext_resource type="Script" path="res://Player/Base/Projectile.cs" id="1_ivbjp"]
[ext_resource type="Texture2D" uid="uid://crlvrwo2l11ja" path="res://Textures/Projectiles/Projectile_Pisces_MultiAttack.png" id="2_a612r"]
[ext_resource type="AudioStream" uid="uid://cw1jlubd7wmw6" path="res://Audio/SFX/blue laser.wav" id="2_oxtlx"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_eme14"]
radius = 0.3
[sub_resource type="CylinderShape3D" id="CylinderShape3D_752q2"]
radius = 0.3
[sub_resource type="Curve3D" id="Curve3D_h8ghr"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.008, 0, -5),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ebbqv"]
radius = 0.3
[node name="ShotgunBullet" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.73894, 0)
script = ExtResource("1_0khuu")
Cooldown = 0.5
script = ExtResource("1_ivbjp")
Cooldown = 1.0
_soundEffect = ExtResource("2_oxtlx")
_projectileSpeed = 15.0
[node name="RigidBody3D" type="RigidBody3D" parent="."]
transform = Transform3D(0.99863, 0, -0.052336, 0, 1, 0, 0.052336, 0, 0.99863, -0.334469, 0, 0)
[node name="Center Shot" type="Path3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.25)
top_level = true
curve = SubResource("Curve3D_h8ghr")
[node name="PathFollow3D" type="PathFollow3D" parent="Center Shot"]
transform = Transform3D(-0.999998, 0, 0.00159994, 0, 1, 0, -0.00159994, 0, -0.999998, 0, 0, 0)
loop = false
tilt_enabled = false
[node name="Hitbox" type="RigidBody3D" parent="Center Shot/PathFollow3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00512208, 0, 0.096)
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
@@ -30,52 +40,66 @@ max_contacts_reported = 1000
contact_monitor = true
can_sleep = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
shape = SubResource("CylinderShape3D_eme14")
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D/CollisionShape3D"]
axis = 1
texture = ExtResource("2_a612r")
[node name="RigidBody3D2" type="RigidBody3D" parent="."]
transform = Transform3D(0.99863, 0, 0.052336, 0, 1, 0, -0.052336, 0, 0.99863, 0.463951, 0, 0)
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
continuous_cd = true
max_contacts_reported = 1000
contact_monitor = true
can_sleep = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D2"]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
shape = SubResource("CylinderShape3D_752q2")
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D2/CollisionShape3D"]
axis = 1
texture = ExtResource("2_a612r")
[node name="RigidBody3D3" type="RigidBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0600076, 0, -0.345734)
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
continuous_cd = true
max_contacts_reported = 1000
contact_monitor = true
can_sleep = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D3"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Center Shot/PathFollow3D/Hitbox"]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
shape = SubResource("CylinderShape3D_ebbqv")
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D3/CollisionShape3D"]
[node name="Sprite3D" type="Sprite3D" parent="Center Shot/PathFollow3D/Hitbox/CollisionShape3D"]
axis = 1
texture = ExtResource("2_a612r")
[node name="TTL" type="Timer" parent="."]
process_callback = 0
autostart = true
[node name="Left Shot" type="Path3D" parent="."]
transform = Transform3D(0.984808, 0, 0.173648, 0, 1, 0, -0.173648, 0, 0.984808, -0.462206, 0, -0.1)
top_level = true
curve = SubResource("Curve3D_h8ghr")
[connection signal="timeout" from="TTL" to="." method="OnTimeToLiveTimeout"]
[node name="PathFollow3D" type="PathFollow3D" parent="Left Shot"]
transform = Transform3D(-0.999998, 0, 0.00159994, 0, 1, 0, -0.00159994, 0, -0.999998, 0, 0, 0)
loop = false
tilt_enabled = false
[node name="Hitbox" type="RigidBody3D" parent="Left Shot/PathFollow3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03827, 0, 0.0309103)
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
continuous_cd = true
max_contacts_reported = 1000
contact_monitor = true
can_sleep = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="Left Shot/PathFollow3D/Hitbox"]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
shape = SubResource("CylinderShape3D_ebbqv")
[node name="Sprite3D" type="Sprite3D" parent="Left Shot/PathFollow3D/Hitbox/CollisionShape3D"]
axis = 1
texture = ExtResource("2_a612r")
[node name="Right Shot" type="Path3D" parent="."]
transform = Transform3D(0.984808, 0, -0.173648, 0, 1, 0, 0.173648, 0, 0.984808, 0.426491, 0, 0)
top_level = true
curve = SubResource("Curve3D_h8ghr")
[node name="PathFollow3D" type="PathFollow3D" parent="Right Shot"]
transform = Transform3D(-0.999998, 0, 0.00159994, 0, 1, 0, -0.00159994, 0, -0.999998, 0, 0, 0)
loop = false
tilt_enabled = false
[node name="Hitbox" type="RigidBody3D" parent="Right Shot/PathFollow3D"]
transform = Transform3D(-1, 0, -0.00159994, 0, 1, 0, 0.00159994, 0, -1, -0.06, 0, 0.096)
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
continuous_cd = true
max_contacts_reported = 1000
contact_monitor = true
can_sleep = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="Right Shot/PathFollow3D/Hitbox"]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, -0.00941685, 0, -0.0539098)
shape = SubResource("CylinderShape3D_ebbqv")
[node name="Sprite3D" type="Sprite3D" parent="Right Shot/PathFollow3D/Hitbox/CollisionShape3D"]
axis = 1
texture = ExtResource("2_a612r")

View File

@@ -1,19 +1,36 @@
[gd_scene load_steps=5 format=3 uid="uid://cyn2wn6ffsnu7"]
[gd_scene load_steps=6 format=3 uid="uid://cyn2wn6ffsnu7"]
[ext_resource type="Script" path="res://Player/Pisces/Attacks/SingleShot.cs" id="1_18l5k"]
[ext_resource type="Script" path="res://Player/Base/Projectile.cs" id="1_62kpd"]
[ext_resource type="AudioStream" uid="uid://cw1jlubd7wmw6" path="res://Audio/SFX/blue laser.wav" id="2_7lbn3"]
[ext_resource type="Texture2D" uid="uid://kecmkchurnin" path="res://Textures/Projectiles/Projectile_Pisces_SingleAttack.png" id="2_d8lwd"]
[sub_resource type="Curve3D" id="Curve3D_do6j1"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.008, 0, -5),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2
[sub_resource type="CylinderShape3D" id="CylinderShape3D_njobr"]
radius = 0.3
[node name="Single" type="Node3D"]
script = ExtResource("1_18l5k")
Cooldown = 0.3
script = ExtResource("1_62kpd")
Cooldown = 1.0
_soundEffect = ExtResource("2_7lbn3")
_projectileSpeed = 10.0
[node name="RigidBody3D" type="RigidBody3D" parent="."]
[node name="Center Shot" type="Path3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, -0.25)
top_level = true
curve = SubResource("Curve3D_do6j1")
[node name="PathFollow3D" type="PathFollow3D" parent="Center Shot"]
transform = Transform3D(-0.999998, 0, 0.00159994, 0, 1, 0, -0.00159994, 0, -0.999998, 0, 0, 0)
loop = false
tilt_enabled = false
[node name="Hitbox" type="RigidBody3D" parent="Center Shot/PathFollow3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
collision_layer = 34
collision_mask = 34
gravity_scale = 0.0
@@ -22,19 +39,12 @@ max_contacts_reported = 1000
contact_monitor = true
can_sleep = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.644825, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Center Shot/PathFollow3D/Hitbox"]
transform = Transform3D(0.5, 0, -7.10543e-15, 0, 0.5, 0, 7.10543e-15, 0, 0.5, 0, 0, 0)
shape = SubResource("CylinderShape3D_njobr")
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D/CollisionShape3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.31565, 0.765425, 0.303541)
[node name="Sprite3D" type="Sprite3D" parent="Center Shot/PathFollow3D/Hitbox/CollisionShape3D"]
transform = Transform3D(1, 0, -3.55271e-14, 0, 1, 0, 3.55271e-14, 0, 1, -0.299847, 0, 0.288742)
centered = false
axis = 1
texture = ExtResource("2_d8lwd")
[node name="TTL" type="Timer" parent="."]
process_callback = 0
wait_time = 0.8
autostart = true
[connection signal="timeout" from="TTL" to="." method="OnTimeToLiveTimeout"]

View File

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

View File

@@ -2,24 +2,9 @@ using Godot;
public partial class CutterShot : Projectile
{
[Export]
private PathFollow3D _pathFollow;
[Export]
private Sprite3D _sprite;
public override void _Ready()
{
base._Ready();
_pathFollow = GetNode<PathFollow3D>("Path3D/PathFollow3D");
}
public override void _PhysicsProcess(double delta)
{
_pathFollow.Progress += 10f * (float)delta;
if (Mathf.IsEqualApprox(_pathFollow.ProgressRatio, 1.0f))
QueueFree();
}
public override void _Process(double delta)
{
_sprite.RotateY(25);

View File

@@ -14,13 +14,12 @@ point_count = 4
[sub_resource type="CylinderShape3D" id="CylinderShape3D_mgm2i"]
height = 8.481
[node name="CutterShot" type="Node3D" node_paths=PackedStringArray("_pathFollow", "_sprite")]
[node name="CutterShot" type="Node3D" node_paths=PackedStringArray("_sprite")]
script = ExtResource("1_inha4")
_pathFollow = NodePath("Path3D/PathFollow3D")
_sprite = NodePath("Path3D/PathFollow3D/RigidBody3D/Sprite3D")
_sprite = NodePath("Path3D/PathFollow3D/RigidBody3D/CollisionShape3D/Sprite3D")
Cooldown = 0.3
_projectileSpeed = 3.0
_soundEffect = ExtResource("2_u4aoe")
_projectileSpeed = 0.1
[node name="Path3D" type="Path3D" parent="."]
top_level = true
@@ -44,16 +43,9 @@ can_sleep = false
transform = Transform3D(0.999999, 0, 1.19209e-07, 0, 1, 0, -1.19209e-07, 0, 0.999999, 0, 0, 0)
shape = SubResource("CylinderShape3D_mgm2i")
[node name="Sprite3D" type="Sprite3D" parent="Path3D/PathFollow3D/RigidBody3D"]
[node name="Sprite3D" type="Sprite3D" parent="Path3D/PathFollow3D/RigidBody3D/CollisionShape3D"]
transform = Transform3D(0.156513, 0, 0.124514, 0, 0.2, 0, -0.124514, 0, 0.156513, 0, 0, 0)
pixel_size = 0.03
axis = 1
double_sided = false
texture = ExtResource("2_tqxh6")
[node name="TTL" type="Timer" parent="."]
process_callback = 0
wait_time = 0.8
autostart = true
[connection signal="timeout" from="TTL" to="." method="OnTimeToLiveTimeout"]

View File

@@ -14,13 +14,12 @@ point_count = 4
[sub_resource type="CylinderShape3D" id="CylinderShape3D_mgm2i"]
height = 8.481
[node name="CutterShot" type="Node3D" node_paths=PackedStringArray("_pathFollow", "_sprite")]
[node name="CutterShot" type="Node3D" node_paths=PackedStringArray("_sprite")]
script = ExtResource("1_7xtlh")
_pathFollow = NodePath("Path3D/PathFollow3D")
_sprite = NodePath("Path3D/PathFollow3D/RigidBody3D/CollisionShape3D/Sprite3D")
Cooldown = 0.3
_soundEffect = ExtResource("2_qmvk7")
_projectileSpeed = 3.0
_soundEffect = ExtResource("2_qmvk7")
[node name="Path3D" type="Path3D" parent="."]
top_level = true
@@ -50,10 +49,3 @@ pixel_size = 0.03
axis = 1
double_sided = false
texture = ExtResource("2_6mabu")
[node name="TTL" type="Timer" parent="."]
process_callback = 0
wait_time = 0.8
autostart = true
[connection signal="timeout" from="TTL" to="." method="OnTimeToLiveTimeout"]