WIP: Some updates

This commit is contained in:
2025-02-08 17:04:17 +01:00
parent 89992b1ef4
commit 5ab840cdd8
14 changed files with 253 additions and 168 deletions

View File

@ -19,33 +19,37 @@ var can_shoot: bool = true
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
cooldown_timer.wait_time = cooldown
print("test")
@onready var bullet_trace_distance: Node3D = $BulletTraceDistance
@onready var bullet_trail_end: Node3D = $BulletTrailEnd
@onready var gun_animation = $ShotAnimation
func shoot() -> Error:
var bullet_start_node: Node3D = bullet_trace_distance.find_child("Start")
var bullet_end_node: Node3D = bullet_trace_distance.find_child("End")
gun_animation.play("shot")
if bullet_start_node and bullet_end_node:
var path := "res://scenes/weapon/misc/bullet_trail_generic.tscn"
if not ResourceLoader.exists(path):
return ERR_DOES_NOT_EXIST
var scene: PackedScene = ResourceLoader.load(path)
if not scene.can_instantiate():
return ERR_CANT_OPEN
if can_shoot:
can_shoot = false
var bullet_start_node: Node3D = bullet_trace_distance.find_child("Start")
var bullet_end_node: Node3D = bullet_trace_distance.find_child("End")
gun_animation.play("shot")
cooldown_timer.start()
var node: MeshInstance3D = scene.instantiate()
node.init(bullet_start_node.position, bullet_end_node.position)
#var root := get_tree().get_root()
bullet_start_node.add_child(node)
return OK
else:
push_warning("Couldn't generate a bullet trace, no distance node found")
return ERR_BUG
can_shoot = false
cooldown_timer.start()
if bullet_start_node and bullet_end_node:
var path := "res://scenes/weapon/misc/bullet_trail_generic.tscn"
if not ResourceLoader.exists(path):
return ERR_DOES_NOT_EXIST
var scene: PackedScene = ResourceLoader.load(path)
if not scene.can_instantiate():
return ERR_CANT_OPEN
var node: MeshInstance3D = scene.instantiate()
node.init(bullet_start_node.position, bullet_end_node.position)
#var root := get_tree().get_root()
bullet_start_node.add_child(node)
return OK
else:
push_warning("Couldn't generate a bullet trace, no distance node found")
return ERR_BUG
return OK
# -- TODO: It should not be hardcoded
@ -53,11 +57,16 @@ func set_map_controller(map_node: MapController):
map_controller = map_node
func attack(bullet_starting_point: Node3D):
map_controller.spawn_bullet(bullet_starting_point, bullet_speed, damage)
can_shoot = false
#cooldown_timer.start()
if can_shoot:
can_shoot = false
map_controller.spawn_bullet(bullet_starting_point, bullet_speed, damage)
cooldown_timer.start()
func make_invisible() -> void:
for child in find_children("*"):
if child is MeshInstance3D:
child.set_layer_mask_value(1, false)
child.set_layer_mask_value(20, false)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=58 format=4 uid="uid://wu6qyd0aqeib"]
[gd_scene load_steps=59 format=4 uid="uid://wu6qyd0aqeib"]
[ext_resource type="Script" path="res://scenes/weapon/generic_weapon_controller.gd" id="1_h1xyo"]
[ext_resource type="PackedScene" uid="uid://bjyltbtx45cqs" path="res://scenes/weapon/misc/bullet_trace_distance.tscn" id="3_5ff4y"]
[ext_resource type="PackedScene" uid="uid://dab7jttp7ywfh" path="res://scenes/weapon/guns/ak/gun.tscn" id="3_q7t3c"]
[ext_resource type="AudioStream" uid="uid://prh2ip5vkpyu" path="res://assets/audio/weapon/generic_gun_sound.mp3" id="4_v0f30"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tg27p"]
@ -640,7 +641,7 @@ _data = {
[node name="WithHands" type="Node3D"]
script = ExtResource("1_h1xyo")
damage = 50
cooldown = 1.0
cooldown = 0.15
mag_capacity = 30
[node name="HandsMount" type="Node3D" parent="."]
@ -872,4 +873,7 @@ process_callback = 0
wait_time = 10.0
one_shot = true
[node name="Sound" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("4_v0f30")
[connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"]