Skip to content

Commit

Permalink
Merge pull request #151 from brian-holsters/enhancement/wieldable_dec…
Browse files Browse the repository at this point in the history
…ouple - READ NOTES

This changes a few things in the PlayerInteractionComponent and the InventoryItem script, but should otherwise be very straight forward.
  • Loading branch information
Phazorknight authored Apr 8, 2024
2 parents ce3c4d9 + c426d1d commit c0ad88c
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 74 deletions.
20 changes: 12 additions & 8 deletions COGITO/Components/PlayerInteractionComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var is_changing_wieldables : bool = false #Used to avoid any input acitons while

## List of Wieldable nodes
@export var wieldable_nodes : Array[Node]
@export var wieldable_container : Node3D
# Various variables used for wieldable handling
var equipped_wieldable_item = null
var equipped_wieldable_node = null
Expand Down Expand Up @@ -168,14 +169,15 @@ func equip_wieldable(wieldable_item:WieldableItemPD):
if wieldable_item != null:
equipped_wieldable_item = wieldable_item #Set Inventory Item reference
# Set Wieldable node reference
for wieldable_node in wieldable_nodes:
if wieldable_node.item_reference == equipped_wieldable_item:
equipped_wieldable_node = wieldable_node
print("PIC: Found ", equipped_wieldable_item.name, " in wieldable node array: ", wieldable_node.name)
equipped_wieldable_node.equip(self)
is_wielding = true
await get_tree().create_timer(equipped_wieldable_node.animation_player.current_animation_length).timeout
is_changing_wieldables = false
var wieldable_node = wieldable_item.build_wieldable_scene()
wieldable_container.add_child(wieldable_node)
equipped_wieldable_node = wieldable_node
equipped_wieldable_node.item_reference = wieldable_item
print("PIC: Found ", equipped_wieldable_item.name, " in wieldable node array: ", wieldable_node.name)
equipped_wieldable_node.equip(self)
is_wielding = true
await get_tree().create_timer(equipped_wieldable_node.animation_player.current_animation_length).timeout
is_changing_wieldables = false
else:
is_changing_wieldables = false

Expand All @@ -190,6 +192,8 @@ func change_wieldable_to(next_wieldable: InventoryItemPD):
if equipped_wieldable_node.animation_player.is_playing(): #Wait until unequip animation finishes.
await get_tree().create_timer(equipped_wieldable_node.animation_player.current_animation_length).timeout
equipped_wieldable_item = null
if equipped_wieldable_node != null:
equipped_wieldable_node.queue_free()
equipped_wieldable_node = null
is_wielding = false
equip_wieldable(next_wieldable)
Expand Down
2 changes: 0 additions & 2 deletions COGITO/InventoryPD/CustomResources/AmmoItemPD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ extends InventoryItemPD
class_name AmmoItemPD

@export_group("Ammo settings")
## The item that this item is ammunition for.
@export var target_item_ammo : WieldableItemPD = null
## The amount one item addes to the target item charge. For bullets this should be 1.
@export var reload_amount : int = 1

Expand Down
7 changes: 7 additions & 0 deletions COGITO/InventoryPD/CustomResources/WieldableItemPD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class_name WieldableItemPD
signal charge_changed()

@export_group("Wieldable settings")
@export var wieldable_scene : PackedScene
## Icon that is displayed on the HUD when item is wielded. If NULL, the item icon will be used instead.
@export var wieldable_data_icon : Texture2D
## Check this if your wieldable doesn't use reload (for example melee weapons)
Expand Down Expand Up @@ -127,3 +128,9 @@ func save():
"charge_current" : charge_current
}
return saved_item_data


func build_wieldable_scene():
var scene = wieldable_scene.instantiate()
scene.item_reference = self
return scene
4 changes: 1 addition & 3 deletions COGITO/InventoryPD/Items/Cogito_Battery.tres
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=7 format=3 uid="uid://cupby6uqaftvv"]
[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=6 format=3 uid="uid://cupby6uqaftvv"]

[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/AmmoItemPD.gd" id="1_3ov2u"]
[ext_resource type="Texture2D" uid="uid://cg5knuav7df4o" path="res://COGITO/Assets/Graphics/HintIcons/Hint_X.png" id="1_54cn8"]
[ext_resource type="Texture2D" uid="uid://c0h1s1g4g1q56" path="res://COGITO/Assets/Graphics/ItemIcons/CogitoBattery.png" id="1_fjosn"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_lxwux"]
[ext_resource type="Resource" uid="uid://ckvdkigvwowm5" path="res://COGITO/InventoryPD/Items/Cogito_Flashlight.tres" id="3_myi62"]
[ext_resource type="AudioStream" uid="uid://bnqnuewmntcyp" path="res://COGITO/Assets/Audio/Kenney/UiAudio/error_008.ogg" id="5_tfubv"]

[resource]
script = ExtResource("1_3ov2u")
target_item_ammo = ExtResource("3_myi62")
reload_amount = 10
name = "Battery"
description = "Can be combined with the Flashlight. Non-rechargeable."
Expand Down
4 changes: 3 additions & 1 deletion COGITO/InventoryPD/Items/Cogito_Dart.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://c6rpnmo1y1cw5"]
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://c6rpnmo1y1cw5"]

[ext_resource type="Texture2D" uid="uid://bubcgr2q03ert" path="res://COGITO/Assets/Graphics/ItemIcons/Dart.png" id="1_m1vko"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="1_ub1do"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_sof2n"]
[ext_resource type="PackedScene" uid="uid://1vnxo4ya6yjr" path="res://COGITO/Wieldables/throw_dart.tscn" id="4_dlpol"]

[resource]
script = ExtResource("1_ub1do")
wieldable_scene = ExtResource("4_dlpol")
no_reload = true
charge_max = 1.0
ammo_item_name = "Dart"
Expand Down
4 changes: 3 additions & 1 deletion COGITO/InventoryPD/Items/Cogito_Flashlight.tres
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://ckvdkigvwowm5"]
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=6 format=3 uid="uid://ckvdkigvwowm5"]

[ext_resource type="Texture2D" uid="uid://heih3rs4r4gt" path="res://COGITO/Assets/Graphics/ItemIcons/CogitoFlashlight.png" id="1_f43pq"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_h6bnx"]
[ext_resource type="Texture2D" uid="uid://4xstvhrf4r2h" path="res://COGITO/Assets/Graphics/BatteryIcon.png" id="3_ea2qf"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_f88a5"]
[ext_resource type="PackedScene" uid="uid://5r8icl42jumy" path="res://COGITO/Wieldables/flashlight.tscn" id="5_ty4ey"]

[resource]
script = ExtResource("2_h6bnx")
wieldable_scene = ExtResource("5_ty4ey")
wieldable_data_icon = ExtResource("3_ea2qf")
no_reload = false
charge_max = 100.0
Expand Down
4 changes: 1 addition & 3 deletions COGITO/InventoryPD/Items/Cogito_FoamBullets.tres
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=6 format=3 uid="uid://bqhbrpnp2tt08"]
[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=5 format=3 uid="uid://bqhbrpnp2tt08"]

[ext_resource type="Texture2D" uid="uid://cxvxq8hy53ih5" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_FoamBullets.png" id="1_efcmi"]
[ext_resource type="Texture2D" uid="uid://cg5knuav7df4o" path="res://COGITO/Assets/Graphics/HintIcons/Hint_X.png" id="1_p472b"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/AmmoItemPD.gd" id="3_fjkqh"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="4_2hhqx"]
[ext_resource type="Resource" uid="uid://lc5uq2e6ldah" path="res://COGITO/InventoryPD/Items/Cogito_Pistol.tres" id="5_cl3nd"]

[resource]
script = ExtResource("3_fjkqh")
target_item_ammo = ExtResource("5_cl3nd")
reload_amount = 1
name = "Foam Bullets"
description = "Very visible but not very dangerous. Have a tendency to vanish."
Expand Down
4 changes: 1 addition & 3 deletions COGITO/InventoryPD/Items/Cogito_LaserAmmo.tres
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=5 format=3 uid="uid://cvupo3p844nh2"]
[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=4 format=3 uid="uid://cvupo3p844nh2"]

[ext_resource type="Texture2D" uid="uid://uj2uowrvb2ni" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_LaserAmmo.png" id="1_6hnrl"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/AmmoItemPD.gd" id="1_opcg5"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_qv1dk"]
[ext_resource type="Resource" uid="uid://txiu5yxexevm" path="res://COGITO/InventoryPD/Items/Cogito_LaserRifle.tres" id="4_37gcd"]

[resource]
script = ExtResource("1_opcg5")
target_item_ammo = ExtResource("4_37gcd")
reload_amount = 50
name = "Laser Ammo"
description = "Tends to get hot. One clip has a charge of 50."
Expand Down
4 changes: 3 additions & 1 deletion COGITO/InventoryPD/Items/Cogito_LaserRifle.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://txiu5yxexevm"]
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://txiu5yxexevm"]

[ext_resource type="Texture2D" uid="uid://bnqyy1c46mlfw" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_LaserRifle.png" id="1_62c38"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_o1rdd"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_yhudh"]
[ext_resource type="PackedScene" uid="uid://bb8pm2nk8hwon" path="res://COGITO/Wieldables/laser_rifle.tscn" id="4_wbhgr"]

[resource]
script = ExtResource("2_o1rdd")
wieldable_scene = ExtResource("4_wbhgr")
no_reload = false
charge_max = 100.0
ammo_item_name = "Laser Ammo"
Expand Down
4 changes: 3 additions & 1 deletion COGITO/InventoryPD/Items/Cogito_Pickaxe.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://bp6xhd3rkh7tl"]
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://s2y3u88qdau3"]

[ext_resource type="Texture2D" uid="uid://h6c4g2wtkb48" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_Pickaxe.png" id="1_a7clm"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="1_fay77"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_5g3cg"]
[ext_resource type="PackedScene" uid="uid://dxxemvynrimqw" path="res://COGITO/Wieldables/pickaxe.tscn" id="4_cgf4o"]

[resource]
script = ExtResource("1_fay77")
wieldable_scene = ExtResource("4_cgf4o")
no_reload = true
charge_max = 1.0
ammo_item_name = ""
Expand Down
16 changes: 9 additions & 7 deletions COGITO/InventoryPD/Items/Cogito_Pistol.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://lc5uq2e6ldah"]
[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://lc5uq2e6ldah"]

[ext_resource type="Texture2D" uid="uid://78js4558o61m" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_Pistol.png" id="1_t40ae"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_otaa7"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_5o4ls"]
[ext_resource type="Texture2D" uid="uid://78js4558o61m" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_Pistol.png" id="1_dj2ew"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_dk2he"]
[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_weko3"]
[ext_resource type="PackedScene" uid="uid://dgtjml2t3hdvx" path="res://COGITO/Wieldables/toy_pistol.tscn" id="4_f2ej1"]

[resource]
script = ExtResource("2_otaa7")
script = ExtResource("2_dk2he")
wieldable_scene = ExtResource("4_f2ej1")
no_reload = false
charge_max = 10.0
ammo_item_name = "Foam Bullets"
Expand All @@ -14,9 +16,9 @@ wieldable_range = 10.0
wieldable_damage = 1.0
name = "Foam Pistol"
description = "There's a reason it looks like a toy. Shoots foam bullets."
icon = ExtResource("1_t40ae")
icon = ExtResource("1_dj2ew")
is_stackable = false
stack_size = 0
drop_scene = "res://COGITO/PrefabScenes/Pickups/pickup_pistol.tscn"
hint_text_on_use = ""
sound_pickup = ExtResource("3_5o4ls")
sound_pickup = ExtResource("3_weko3")
4 changes: 2 additions & 2 deletions COGITO/PrefabScenes/Pickups/pickup_dart.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ metallic = 1.0
height = 0.28
radius = 0.05

[sub_resource type="Resource" id="Resource_5gvqf"]
[sub_resource type="Resource" id="Resource_8p8de"]
resource_local_to_scene = true
script = ExtResource("4_qk8k6")
inventory_item = ExtResource("3_ohc35")
Expand Down Expand Up @@ -114,7 +114,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.14, 0)
shape = SubResource("CylinderShape3D_xbicr")

[node name="PickupComponent" parent="." instance=ExtResource("2_u01ym")]
slot_data = SubResource("Resource_5gvqf")
slot_data = SubResource("Resource_8p8de")

[node name="Lifespan" type="Timer" parent="."]

Expand Down
22 changes: 4 additions & 18 deletions COGITO/PrefabScenes/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=27 format=3 uid="uid://kicjwmh02uwf"]
[gd_scene load_steps=22 format=3 uid="uid://kicjwmh02uwf"]

[ext_resource type="Script" path="res://COGITO/Scripts/player.gd" id="1_wkneb"]
[ext_resource type="Resource" uid="uid://ev2xuamhfojm" path="res://COGITO/InventoryPD/Inventories/PlayerInventory.tres" id="2_qleua"]
Expand All @@ -8,18 +8,13 @@
[ext_resource type="AnimationLibrary" uid="uid://cdchpsv104er2" path="res://COGITO/Assets/Animations/player_eyes.tres" id="4_juktk"]
[ext_resource type="AudioStream" uid="uid://crj07wq4oocwi" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep01.ogg" id="5_6htai"]
[ext_resource type="PackedScene" uid="uid://ce7bjv28uakxl" path="res://COGITO/Components/Attributes/StaminaAttribute.tscn" id="5_dmlhq"]
[ext_resource type="PackedScene" uid="uid://5r8icl42jumy" path="res://COGITO/Wieldables/flashlight.tscn" id="5_ukw1v"]
[ext_resource type="PackedScene" uid="uid://wtf1fqndii2p" path="res://COGITO/Components/Attributes/VisibilityAttribute.tscn" id="6_kao4w"]
[ext_resource type="PackedScene" uid="uid://dgtjml2t3hdvx" path="res://COGITO/Wieldables/toy_pistol.tscn" id="6_lwwgx"]
[ext_resource type="AudioStream" uid="uid://dewyukd562k37" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep02.ogg" id="6_nrttm"]
[ext_resource type="PackedScene" uid="uid://bb8pm2nk8hwon" path="res://COGITO/Wieldables/laser_rifle.tscn" id="7_cn6iu"]
[ext_resource type="AudioStream" uid="uid://c5kfw4o57foju" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep03.ogg" id="7_swbyy"]
[ext_resource type="PackedScene" uid="uid://cetc123v5gnff" path="res://COGITO/Components/Attributes/SanityAttribute.tscn" id="7_toa7v"]
[ext_resource type="AudioStream" uid="uid://b4mt1tuxo2144" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep04.ogg" id="8_2tp8b"]
[ext_resource type="PackedScene" uid="uid://dxxemvynrimqw" path="res://COGITO/Wieldables/pickaxe.tscn" id="12_03s1j"]
[ext_resource type="AudioStream" uid="uid://b7wmxwvtbpfu1" path="res://COGITO/Assets/Audio/537275__laughingfish78__dirt-sliding.ogg" id="13_jr246"]
[ext_resource type="PackedScene" uid="uid://dy3tudla5p2nc" path="res://COGITO/Components/PlayerInteractionComponent.tscn" id="13_rawn6"]
[ext_resource type="PackedScene" uid="uid://1vnxo4ya6yjr" path="res://COGITO/Wieldables/throw_dart.tscn" id="14_xn6yt"]
[ext_resource type="Script" path="res://COGITO/DynamicFootstepSystem/Scripts/footstep_surface_detector.gd" id="16_a6uam"]
[ext_resource type="AudioStream" uid="uid://dc03jiw2a6y3j" path="res://COGITO/DynamicFootstepSystem/FootstepProfiles/generic_footstep_profile.tres" id="17_rmtvn"]
[ext_resource type="Resource" uid="uid://ca0q2t6w08ubh" path="res://COGITO/DynamicFootstepSystem/FootstepMaterialLibrary/sample_footstep_material_library.tres" id="18_q6u2l"]
Expand Down Expand Up @@ -105,16 +100,7 @@ target_position = Vector3(0, 0, -2.5)
collision_mask = 3

[node name="Wieldables" type="Node3D" parent="Neck/Head"]

[node name="Flashlight" parent="Neck/Head/Wieldables" instance=ExtResource("5_ukw1v")]

[node name="Toy Pistol" parent="Neck/Head/Wieldables" instance=ExtResource("6_lwwgx")]

[node name="Laser Rifle" parent="Neck/Head/Wieldables" instance=ExtResource("7_cn6iu")]

[node name="Pickaxe" parent="Neck/Head/Wieldables" instance=ExtResource("12_03s1j")]

[node name="Dart" parent="Neck/Head/Wieldables" instance=ExtResource("14_xn6yt")]
unique_name_in_owner = true

[node name="SlidingTimer" type="Timer" parent="."]
wait_time = 1.5
Expand All @@ -136,10 +122,10 @@ one_shot = true
wait_time = 0.5
one_shot = true

[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("interaction_raycast", "carryable_position", "wieldable_nodes") instance=ExtResource("13_rawn6")]
[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("interaction_raycast", "carryable_position", "wieldable_container") instance=ExtResource("13_rawn6")]
interaction_raycast = NodePath("../Neck/Head/Eyes/Camera/InteractionRaycast")
carryable_position = NodePath("../CarryablePosition")
wieldable_nodes = [NodePath("../Neck/Head/Wieldables/Flashlight"), NodePath("../Neck/Head/Wieldables/Toy Pistol"), NodePath("../Neck/Head/Wieldables/Laser Rifle"), NodePath("../Neck/Head/Wieldables/Pickaxe"), NodePath("../Neck/Head/Wieldables/Dart")]
wieldable_container = NodePath("../Neck/Head/Wieldables")

[connection signal="animation_finished" from="Neck/Head/Eyes/AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
[connection signal="timeout" from="SlidingTimer" to="." method="_on_sliding_timer_timeout"]
2 changes: 1 addition & 1 deletion COGITO/Scripts/Cogito_Wieldable.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class_name CogitoWieldable

@export_group("General Wieldable Settings")
## Item resource that this wieldable refers to.
@export var item_reference : WieldableItemPD
var item_reference : WieldableItemPD
## Visible parts of the wieldable. Used to hide/show on equip/unequip.
@export var wieldable_mesh : Node3D

Expand Down
2 changes: 2 additions & 0 deletions COGITO/Scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ var slide_audio_player : AudioStreamPlayer3D

@onready var self_rid: RID = self.get_rid()
@onready var test_motion_result: PhysicsTestMotionResult3D = PhysicsTestMotionResult3D.new()

@onready var wieldables = %Wieldables
#endregion


Expand Down
21 changes: 14 additions & 7 deletions COGITO/Wieldables/Wieldable_Throwable.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extends CogitoWieldable


@export_group("Throwable Settings")
## Path to the projectile prefab scene
@export var projectile_prefab : PackedScene
## Leave empty if projectile and pickup are the same scene
@export var projectile_override: PackedScene
## Speed the projectile spawns with
@export var projectile_velocity : float
## Node the projectile spawns at
Expand Down Expand Up @@ -67,8 +68,14 @@ func action_primary(_passed_item_reference : InventoryItemPD, _is_released: bool
var Direction = (_camera_collision - bullet_point.get_global_transform().origin).normalized()

# Spawning projectile
var Projectile = projectile_prefab.instantiate()
bullet_point.add_child(Projectile)
Projectile.damage_amount = _passed_item_reference.wieldable_damage
Projectile.set_linear_velocity(Direction * projectile_velocity)
Projectile.reparent(get_tree().get_current_scene())
var projectile = instantiate_projectile()
bullet_point.add_child(projectile)
projectile.damage_amount = _passed_item_reference.wieldable_damage
projectile.set_linear_velocity(Direction * projectile_velocity)
projectile.reparent(get_tree().get_current_scene())


func instantiate_projectile() -> Node3D:
if projectile_override != null:
return projectile_override.instantiate()
return load(item_reference.drop_scene).instantiate()
5 changes: 1 addition & 4 deletions COGITO/Wieldables/flashlight.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://5r8icl42jumy"]
[gd_scene load_steps=7 format=3 uid="uid://5r8icl42jumy"]

[ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Flashlight.gd" id="1_pak3j"]
[ext_resource type="AudioStream" uid="uid://dsp8iwkwq2rlu" path="res://COGITO/Assets/Audio/Kenney/UiAudio/switch1.ogg" id="2_dm0bj"]
[ext_resource type="Resource" uid="uid://ckvdkigvwowm5" path="res://COGITO/InventoryPD/Items/Cogito_Flashlight.tres" id="3_2q6j0"]
[ext_resource type="AnimationLibrary" uid="uid://dtnyvbl2d4lxg" path="res://COGITO/Animations/Wieldables/Wieldable_Flashlight.res" id="4_sk1pk"]
[ext_resource type="Script" path="res://COGITO/Assets/Shader/ViewmodelSpace.gd" id="5_kuso5"]

Expand All @@ -22,7 +21,6 @@ transform = Transform3D(-3.61999e-06, 0, 1, 0, 1, 0, -1, 0, -3.61999e-06, 0.3258
script = ExtResource("1_pak3j")
drain_rate = 4.0
switch_sound = ExtResource("2_dm0bj")
item_reference = ExtResource("3_2q6j0")
wieldable_mesh = NodePath("Flashlight_Mesh")
anim_equip = "Wieldable_Flashlight/equip"
anim_unequip = "Wieldable_Flashlight/unequip"
Expand All @@ -45,7 +43,6 @@ spot_range = 8.0
spot_angle = 30.0

[node name="Flashlight_Mesh" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
script = ExtResource("5_kuso5")

[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Flashlight_Mesh"]
Expand Down
Loading

0 comments on commit c0ad88c

Please sign in to comment.