Make it possible to dynamically set weapon parans

This commit is contained in:
2025-01-28 10:51:45 +01:00
parent 06a1d28e42
commit b54ffaeb0d
11 changed files with 106 additions and 83 deletions

View File

@ -1,7 +1,7 @@
extends Node3D
const SPEED = 200 # 200
@export var speed: int = 0
@export var damage: int = 0
@onready var mesh = $RigidBody3D/MeshInstance3D
@onready var rigid_body_3d: RigidBody3D = $RigidBody3D
@onready var ray = $RigidBody3D/RayCast3D
@ -15,9 +15,9 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var time_per_frame: float = 1 / Engine.get_frames_per_second()
var distance: float = time_per_frame * SPEED * 1.5
var distance: float = time_per_frame * speed * 1.5
ray.target_position.z = distance
position += transform.basis * Vector3(0, 0, SPEED) * delta
position += transform.basis * Vector3(0, 0, speed) * delta
rigid_body_3d.set_use_continuous_collision_detection(true)
#ray.collision_mask = 1
#ray.enabled = 1
@ -26,7 +26,7 @@ func _process(delta):
if collider != null and collider.is_in_group("target"):
ray.get_collider().take_damage()
if collider != null and collider.is_in_group("body"):
ray.get_collider().hit()
ray.get_collider().hit(damage)
rigid_body_3d.visible = false
particles.emitting = true
#if ray.get_collider().is_in_group("body"):

View File

@ -0,0 +1,41 @@
extends Node3D
# ---------------------------------------------------------------------
# Main weapon params
# ---------------------------------------------------------------------
@export var damage: int = 0
# cooldown interval in seconds
@export var cooldown: float = 0
# bullet speed in m/s
@export var bullet_speed: int = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@onready var bullet_trace_distance: Node3D = $BulletTraceDistance
@onready var bullet_trail_end: Node3D = $BulletTrailEnd
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")
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
# -- TODO: It should not be hardcoded
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@ -1,18 +0,0 @@
extends Node3D
const SPEED = 10
@onready var mesh = $Object_10
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
position += transform.basis * Vector3(0, 0, SPEED) * delta
func _on_timer_timeout():
queue_free()

View File

@ -1,6 +1,4 @@
[gd_scene load_steps=5 format=4 uid="uid://dn6imke7vnimn"]
[ext_resource type="Script" path="res://scenes/weapon/guns/ak/bullet.gd" id="1_rbbkb"]
[gd_scene load_steps=4 format=4 uid="uid://dn6imke7vnimn"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ledbj"]
resource_name = "stell"
@ -45,7 +43,6 @@ shadow_mesh = SubResource("ArrayMesh_mgmay")
[node name="Bullet" type="Node3D"]
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
script = ExtResource("1_rbbkb")
[node name="Object_10" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0)

View File

@ -1,10 +0,0 @@
extends MeshInstance3D
var trail_length = 2.0
var speed = 10.0
func _process(delta):
global_transform.origin += transform.basis.z * speed * delta
scale.x = max(scale.x - delta, 100)
scale.y = max(scale.y - delta, 100)
scale.z = max(scale.z - delta, 100)

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=55 format=4 uid="uid://dtvo21mk1webd"]
[ext_resource type="Script" path="res://scenes/weapon/guns/ak/with_hands.gd" id="1_2iqts"]
[ext_resource type="PackedScene" uid="uid://dab7jttp7ywfh" path="res://scenes/weapon/guns/ak/gun.tscn" id="1_aaafm"]
[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"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tg27p"]
@ -553,7 +553,10 @@ blend_shape_mode = 0
shadow_mesh = SubResource("ArrayMesh_he3sr")
[node name="WithHands" type="Node3D"]
script = ExtResource("1_2iqts")
script = ExtResource("1_h1xyo")
damage = 50
cooldown = 0.2
bullet_speed = 200
[node name="Gun" parent="." instance=ExtResource("1_aaafm")]