Skip to content

Commit

Permalink
Add weapon hardpoints, save reusable frigate scene
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jun 27, 2024
1 parent 71a4ddd commit 6566e0c
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 124 deletions.
47 changes: 10 additions & 37 deletions galaxy/star_systems/barnard's_star.tscn
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
[gd_scene load_steps=10 format=3 uid="uid://cghdtnx2qen2u"]
[gd_scene load_steps=5 format=3 uid="uid://cghdtnx2qen2u"]

[ext_resource type="PackedScene" uid="uid://cji43wyk7116p" path="res://celestials/stars/star.tscn" id="1_dt7yu"]
[ext_resource type="Texture2D" uid="uid://bsgwmdcreel60" path="res://celestials/stars/assets/star_red02.png" id="2_xr5lq"]
[ext_resource type="PackedScene" uid="uid://cqxv07b8bwiev" path="res://ships/ship.tscn" id="3_snupf"]
[ext_resource type="Script" path="res://ships/pirate.gd" id="4_cyjdf"]
[ext_resource type="Resource" uid="uid://dmd83o4ylhb0l" path="res://ships/frigate03/frigate03.tres" id="5_shiqq"]
[ext_resource type="ArrayMesh" uid="uid://c2y60nf8m25ka" path="res://ships/frigate03/frigate03_mesh.tres" id="6_jaogd"]

[sub_resource type="BoxShape3D" id="BoxShape3D_akl7r"]
size = Vector3(1.98299, 0.832642, 1.04932)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ce32m"]
shading_mode = 0

[sub_resource type="QuadMesh" id="QuadMesh_cgyha"]
material = SubResource("StandardMaterial3D_ce32m")
size = Vector2(3, 3)
orientation = 1
[ext_resource type="PackedScene" uid="uid://bxggrqus7bst5" path="res://ships/frigate03/frigate03.tscn" id="7_lnhbv"]

[node name="Barnard\'s Star" type="Node3D" groups=["star_system"]]

Expand All @@ -32,29 +19,15 @@ omni_range = 10.0
[node name="Sprite3D" parent="Star" index="2"]
texture = ExtResource("2_xr5lq")

[node name="Frigate" parent="." instance=ExtResource("3_snupf")]
[node name="Frigate" parent="." instance=ExtResource("7_lnhbv")]
transform = Transform3D(0.866897, -1.28496e-16, 0.498488, 3.48787e-16, 1, -3.48787e-16, -0.498488, 4.76228e-16, 0.866897, -8.39, 2.08165e-12, 1.15)
script = ExtResource("4_cyjdf")
detection_range = null
preferred_distance = null
distance_hysteresis = null
fire_range = null
direction_tolerance_deg = null
patrol_radius = null
patrol_target_tolerance = null
ship_def = ExtResource("5_shiqq")
free_when_destroyed = null

[node name="CollisionShape3D" parent="Frigate" index="0"]
transform = Transform3D(-4.63277e-08, 3.48787e-16, 1, 3.48787e-16, 1, -3.48787e-16, -1, 3.48787e-16, -1.07655e-07, 0.00127268, -0.00946045, 0.308623)
shape = SubResource("BoxShape3D_akl7r")

[node name="MeshInstance3D" parent="Frigate" index="1"]
transform = Transform3D(-0.4, 1.39515e-16, 3.49691e-08, 1.39515e-16, 0.4, -1.39515e-16, -3.49691e-08, -1.39515e-16, -0.4, 0, 0, 0.204503)
mesh = ExtResource("6_jaogd")

[node name="MinimapIcon" parent="Frigate" index="2"]
mesh = SubResource("QuadMesh_cgyha")
detection_range = 10.0
preferred_distance = 3.0
distance_hysteresis = 1.5
fire_range = 8.0
direction_tolerance_deg = 10.0
patrol_radius = 10.0
patrol_target_tolerance = 1.0

[editable path="Star"]
[editable path="Frigate"]
83 changes: 21 additions & 62 deletions galaxy/star_systems/wolf_359.tscn
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
[gd_scene load_steps=10 format=3 uid="uid://d3qpe4ne3bgww"]
[gd_scene load_steps=5 format=3 uid="uid://d3qpe4ne3bgww"]

[ext_resource type="PackedScene" uid="uid://cji43wyk7116p" path="res://celestials/stars/star.tscn" id="1_p0ggc"]
[ext_resource type="Texture2D" uid="uid://dh0obx8nl0ltx" path="res://celestials/stars/assets/star_red03.png" id="2_sinon"]
[ext_resource type="PackedScene" uid="uid://cqxv07b8bwiev" path="res://ships/ship.tscn" id="3_myr2k"]
[ext_resource type="PackedScene" uid="uid://bxggrqus7bst5" path="res://ships/frigate03/frigate03.tscn" id="3_1cx0e"]
[ext_resource type="Script" path="res://ships/pirate.gd" id="4_j6bxn"]
[ext_resource type="Resource" uid="uid://dmd83o4ylhb0l" path="res://ships/frigate03/frigate03.tres" id="5_gryh4"]
[ext_resource type="ArrayMesh" uid="uid://c2y60nf8m25ka" path="res://ships/frigate03/frigate03_mesh.tres" id="6_2ysmk"]

[sub_resource type="BoxShape3D" id="BoxShape3D_kxw5i"]
size = Vector3(1.98299, 0.832642, 1.04932)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t5loa"]
shading_mode = 0

[sub_resource type="QuadMesh" id="QuadMesh_fxdwr"]
material = SubResource("StandardMaterial3D_t5loa")
size = Vector2(3, 3)
orientation = 1

[node name="Wolf 359" type="Node3D" groups=["star_system"]]

Expand All @@ -32,54 +19,26 @@ omni_range = 10.0
[node name="Sprite3D" parent="Star" index="2"]
texture = ExtResource("2_sinon")

[node name="Frigate" parent="." instance=ExtResource("3_myr2k")]
transform = Transform3D(-0.155866, 3.98888e-16, 0.987779, 3.48787e-16, 1, -3.48787e-16, -0.987779, 2.9016e-16, -0.155866, 5.29319, 2.08165e-12, -2.13469)
[node name="Frigate" parent="." instance=ExtResource("3_1cx0e")]
transform = Transform3D(-0.287762, -2.33666e-16, -0.957702, 3.48787e-16, 1, -3.48787e-16, 0.957702, -4.34402e-16, -0.287762, -7.88217, 0, -3.99797)
script = ExtResource("4_j6bxn")
detection_range = null
preferred_distance = null
distance_hysteresis = null
fire_range = null
direction_tolerance_deg = null
patrol_radius = null
patrol_target_tolerance = null
ship_def = ExtResource("5_gryh4")
free_when_destroyed = null

[node name="CollisionShape3D" parent="Frigate" index="0"]
transform = Transform3D(-4.63277e-08, 3.48787e-16, 1, 3.48787e-16, 1, -3.48787e-16, -1, 3.48787e-16, -1.07655e-07, 0.00127268, -0.00946045, 0.308623)
shape = SubResource("BoxShape3D_kxw5i")

[node name="MeshInstance3D" parent="Frigate" index="1"]
transform = Transform3D(-0.4, 1.39515e-16, 3.49691e-08, 1.39515e-16, 0.4, -1.39515e-16, -3.49691e-08, -1.39515e-16, -0.4, 0, 0, 0.204503)
mesh = ExtResource("6_2ysmk")

[node name="MinimapIcon" parent="Frigate" index="2"]
mesh = SubResource("QuadMesh_fxdwr")

[node name="Frigate2" parent="." instance=ExtResource("3_myr2k")]
transform = Transform3D(-0.445682, -1.56783e-16, -0.895191, 3.48787e-16, 1, -3.48787e-16, 0.895191, -4.67679e-16, -0.445682, -6.43007, 2.08165e-12, -4.51201)
detection_range = 10.0
preferred_distance = 3.0
distance_hysteresis = 1.5
fire_range = 8.0
direction_tolerance_deg = 10.0
patrol_radius = 10.0
patrol_target_tolerance = 1.0

[node name="Frigate2" parent="." instance=ExtResource("3_1cx0e")]
transform = Transform3D(-0.69814, 4.9322e-16, 0.715961, 3.48787e-16, 1, -3.48787e-16, -0.715961, 6.21555e-18, -0.69814, 5.40376, 0, 0.771966)
script = ExtResource("4_j6bxn")
detection_range = null
preferred_distance = null
distance_hysteresis = null
fire_range = null
direction_tolerance_deg = null
patrol_radius = null
patrol_target_tolerance = null
ship_def = ExtResource("5_gryh4")
free_when_destroyed = null

[node name="CollisionShape3D" parent="Frigate2" index="0"]
transform = Transform3D(-4.63277e-08, 3.48787e-16, 1, 3.48787e-16, 1, -3.48787e-16, -1, 3.48787e-16, -1.07655e-07, 0.00127268, -0.00946045, 0.308623)
shape = SubResource("BoxShape3D_kxw5i")

[node name="MeshInstance3D" parent="Frigate2" index="1"]
transform = Transform3D(-0.4, 1.39515e-16, 3.49691e-08, 1.39515e-16, 0.4, -1.39515e-16, -3.49691e-08, -1.39515e-16, -0.4, 0, 0, 0.204503)
mesh = ExtResource("6_2ysmk")

[node name="MinimapIcon" parent="Frigate2" index="2"]
mesh = SubResource("QuadMesh_fxdwr")
detection_range = 10.0
preferred_distance = 3.0
distance_hysteresis = 1.5
fire_range = 8.0
direction_tolerance_deg = 10.0
patrol_radius = 10.0
patrol_target_tolerance = 1.0

[editable path="Star"]
[editable path="Frigate"]
[editable path="Frigate2"]
8 changes: 3 additions & 5 deletions game.tscn
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
[gd_scene load_steps=38 format=3 uid="uid://sunhu71swcs2"]
[gd_scene load_steps=37 format=3 uid="uid://sunhu71swcs2"]

[ext_resource type="Script" path="res://utils/shader_precompiler.gd" id="1_kgmvv"]
[ext_resource type="Script" path="res://galaxy/hyperspace_controller.gd" id="2_5gj7y"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster.tscn" id="2_bp704"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster_bolt.tscn" id="2_bp704"]
[ext_resource type="Script" path="res://effects/main_camera.gd" id="2_v5hns"]
[ext_resource type="Resource" uid="uid://bcva4l4cpt70c" path="res://galaxy/main_galaxy.tres" id="3_j76v0"]
[ext_resource type="Material" uid="uid://tpd4rufhhe4h" path="res://celestials/starfield/starfield.tres" id="3_vksuy"]
[ext_resource type="Script" path="res://effects/hyperspace/hyperspace_effect.gd" id="4_bmy66"]
[ext_resource type="Script" path="res://galaxy/star_systems/star_system.gd" id="4_oiv78"]
[ext_resource type="AudioStream" uid="uid://cmjfgigj57eie" path="res://effects/hyperspace/hyperspace.ogg" id="5_jhe1g"]
[ext_resource type="PackedScene" uid="uid://cqxv07b8bwiev" path="res://ships/ship.tscn" id="6_8inyn"]
[ext_resource type="PackedScene" uid="uid://cqxv07b8bwiev" path="res://ships/corvette01/corvette01.tscn" id="6_8inyn"]
[ext_resource type="Environment" uid="uid://b7t3opwr35xen" path="res://effects/environment.tres" id="6_srnxb"]
[ext_resource type="Script" path="res://ships/player.gd" id="7_6citj"]
[ext_resource type="Resource" uid="uid://dc468i445pkgd" path="res://ships/corvette01/corvette01.tres" id="8_s4vsk"]
[ext_resource type="PackedScene" uid="uid://2mdsbbko7baw" path="res://galaxy/star_systems/sol.tscn" id="10_vhe4b"]
[ext_resource type="Theme" uid="uid://r4w2xa3q1twa" path="res://gui/theme.tres" id="11_x7io4"]
[ext_resource type="Script" path="res://gui/control_scheme_button.gd" id="12_ti545"]
Expand Down Expand Up @@ -147,7 +146,6 @@ gravity_scale = 1.66533e-16
can_sleep = false
script = ExtResource("7_6citj")
hyperspace_controller = NodePath("../HyperspaceController")
ship_def = ExtResource("8_s4vsk")
free_when_destroyed = false

[node name="AudioListener3D" type="AudioListener3D" parent="Player"]
Expand Down
12 changes: 9 additions & 3 deletions ships/ship.tscn → ships/corvette01/corvette01.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=10 format=3 uid="uid://cqxv07b8bwiev"]
[gd_scene load_steps=11 format=3 uid="uid://cqxv07b8bwiev"]

[ext_resource type="Script" path="res://ships/ship.gd" id="1_wioy5"]
[ext_resource type="ArrayMesh" uid="uid://40a23nnu1j37" path="res://ships/corvette01/corvette01_mesh.tres" id="1_yacfo"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster.tscn" id="2_gae27"]
[ext_resource type="Resource" uid="uid://dc468i445pkgd" path="res://ships/corvette01/corvette01.tres" id="2_20tol"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster_bolt.tscn" id="2_gae27"]
[ext_resource type="PackedScene" uid="uid://cdyo800b83x5i" path="res://effects/explosions/explosion002.tscn" id="2_xcc1t"]
[ext_resource type="Material" uid="uid://dskoto6nul131" path="res://gui/target_overlay_mat.tres" id="4_it73y"]
[ext_resource type="AudioStream" uid="uid://5iqc5o8p02l5" path="res://ships/audio/THRUSTER LOW.wav" id="4_xrdjv"]
Expand All @@ -16,18 +17,20 @@ shading_mode = 0
material = SubResource("StandardMaterial3D_t5loa")
orientation = 1

[node name="Ship" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance") groups=["ships"]]
[node name="Corvette" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance", "weapon_hardpoints") groups=["ships"]]
transform = Transform3D(1, -3.48787e-16, 3.48787e-16, 3.48787e-16, 1, -3.48787e-16, -3.48787e-16, 3.48787e-16, 1, 0, 0, 0)
collision_mask = 2
axis_lock_linear_y = true
axis_lock_angular_x = true
axis_lock_angular_z = true
script = ExtResource("1_wioy5")
ship_def = ExtResource("2_20tol")
bullet = ExtResource("2_gae27")
explosion = ExtResource("2_xcc1t")
thruster_audio = NodePath("AudioStreamPlayer3D")
target_overlay_material = ExtResource("4_it73y")
mesh_instance = NodePath("MeshInstance3D")
weapon_hardpoints = [NodePath("BlasterHardpoint")]

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0)
Expand All @@ -46,3 +49,6 @@ mesh = SubResource("QuadMesh_lxgwo")
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, -6.21724e-17, 6.21724e-17, 0.178253)
stream = ExtResource("4_xrdjv")
volume_db = -40.0

[node name="BlasterHardpoint" type="Node3D" parent="."]
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, 1.62168e-16, -1.62168e-16, -0.464948)
57 changes: 57 additions & 0 deletions ships/frigate03/frigate03.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[gd_scene load_steps=11 format=3 uid="uid://bxggrqus7bst5"]

[ext_resource type="Script" path="res://ships/ship.gd" id="1_wioy5"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster_bolt.tscn" id="2_gae27"]
[ext_resource type="Resource" uid="uid://dmd83o4ylhb0l" path="res://ships/frigate03/frigate03.tres" id="2_lg5km"]
[ext_resource type="PackedScene" uid="uid://cdyo800b83x5i" path="res://effects/explosions/explosion002.tscn" id="2_xcc1t"]
[ext_resource type="Material" uid="uid://dskoto6nul131" path="res://gui/target_overlay_mat.tres" id="4_it73y"]
[ext_resource type="AudioStream" uid="uid://5iqc5o8p02l5" path="res://ships/audio/THRUSTER LOW.wav" id="4_xrdjv"]
[ext_resource type="ArrayMesh" uid="uid://c2y60nf8m25ka" path="res://ships/frigate03/frigate03_mesh.tres" id="6_g7bx0"]

[sub_resource type="BoxShape3D" id="BoxShape3D_quq5g"]
size = Vector3(1.98299, 0.832642, 1.04932)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ce32m"]
shading_mode = 0

[sub_resource type="QuadMesh" id="QuadMesh_plv6r"]
material = SubResource("StandardMaterial3D_ce32m")
size = Vector2(3, 3)
orientation = 1

[node name="Frigate" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance", "weapon_hardpoints") groups=["ships"]]
transform = Transform3D(1, -3.48787e-16, 3.48787e-16, 3.48787e-16, 1, -3.48787e-16, -3.48787e-16, 3.48787e-16, 1, 0, 0, 0)
collision_mask = 2
axis_lock_linear_y = true
axis_lock_angular_x = true
axis_lock_angular_z = true
script = ExtResource("1_wioy5")
ship_def = ExtResource("2_lg5km")
bullet = ExtResource("2_gae27")
explosion = ExtResource("2_xcc1t")
thruster_audio = NodePath("AudioStreamPlayer3D")
target_overlay_material = ExtResource("4_it73y")
mesh_instance = NodePath("MeshInstance3D")
weapon_hardpoints = [NodePath("BlasterHardpoint")]

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(-4.63277e-08, 3.48787e-16, 1, 3.48787e-16, 1, -3.48787e-16, -1, 3.48787e-16, -1.07655e-07, 0.00127268, -0.00946045, 0.308623)
shape = SubResource("BoxShape3D_quq5g")

[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(-0.4, 1.39515e-16, 3.49691e-08, 1.39515e-16, 0.4, -1.39515e-16, -3.49691e-08, -1.39515e-16, -0.4, 3.24163e-24, -3.24163e-24, 0.204503)
mesh = ExtResource("6_g7bx0")
skeleton = NodePath("")

[node name="MinimapIcon" type="MeshInstance3D" parent="."]
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, 0, 0, 0)
layers = 2
mesh = SubResource("QuadMesh_plv6r")

[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, -6.21724e-17, 6.21724e-17, 0.178253)
stream = ExtResource("4_xrdjv")
volume_db = -40.0

[node name="BlasterHardpoint" type="Node3D" parent="."]
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, 2.35838e-16, -2.35838e-16, -0.676166)
8 changes: 7 additions & 1 deletion ships/ship.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class_name Ship
## If false, the ship will instead be made invisible and stop participating in physics and collision calculations. This is mostly useful for the player's ship, which is often expected to exist (even if invisible) by other nodes.
@export var free_when_destroyed: bool = true

## Physical attachments on the ship from which weapons fire.
##
## Indices correspond 1:1 to [member ShipDef.weapons].
@export var weapon_hardpoints: Array[Node3D] = []

## Fires when this ship's hull integrity changes (e.g., due to damage).
signal ship_hull_changed(ship: Ship)

Expand Down Expand Up @@ -117,6 +122,7 @@ func fire() -> void:

func _fire_weapon(idx: int) -> void:
var weapon := self.ship_def.weapons[idx]
var hardpoint := self.weapon_hardpoints[idx]

var now := Time.get_ticks_msec()
if now - self._last_fired_msec[idx] < weapon.fire_interval_msec:
Expand All @@ -131,7 +137,7 @@ func _fire_weapon(idx: int) -> void:
var bullet_instance: RigidBody3D = self.bullet.instantiate()
get_parent().add_child(bullet_instance)
bullet_instance.add_collision_exception_with(self)
bullet_instance.global_transform = self.global_transform
bullet_instance.global_transform = hardpoint.global_transform

bullet_instance.linear_velocity = self.linear_velocity
bullet_instance.apply_central_impulse(bullet_instance.transform.basis * weapon.fire_force * Vector3.FORWARD)
Expand Down
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://lyur31oafltf"
path.s3tc="res://.godot/imported/blaster.png-79cdd86516327c7d7de3d516f4ee9b59.s3tc.ctex"
path.s3tc="res://.godot/imported/blaster_bolt.png-51e8088d9cc70bc060c9dcc8a4668553.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}

[deps]

source_file="res://weapons/blaster/blaster.png"
dest_files=["res://.godot/imported/blaster.png-79cdd86516327c7d7de3d516f4ee9b59.s3tc.ctex"]
source_file="res://weapons/blaster/blaster_bolt.png"
dest_files=["res://.godot/imported/blaster_bolt.png-51e8088d9cc70bc060c9dcc8a4668553.s3tc.ctex"]

[params]

Expand Down
Loading

0 comments on commit 6566e0c

Please sign in to comment.