mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-04-22 21:05:33 +00:00
♻️ move weapons into entities
This commit is contained in:
parent
662cc7d117
commit
b025d8e6f7
12 changed files with 400 additions and 17 deletions
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"]
|
||||
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"]
|
||||
[ext_resource type="Shape3D" path="res://entities/player/collision_shape.tres" id="2_vjqny"]
|
||||
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_vjqny"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://weapons/space_gun/space_gun.tscn" id="4_lhn5w"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn1tcakam5egs" path="res://weapons/space_gun/projectile.tscn" id="5_lvaut"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://entities/weapons/space_gun/space_gun.tscn" id="4_rm831"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn1tcakam5egs" path="res://entities/weapons/space_gun/projectile.tscn" id="5_o1jib"]
|
||||
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://components/health_component.tscn" id="5_t6i6e"]
|
||||
[ext_resource type="Script" path="res://entities/player/player_input.gd" id="6_ymcrr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iff.tscn" id="7_8hc80"]
|
||||
|
|
@ -27,26 +27,26 @@ length = 0.001
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.244668, -0.229311, -0.30332)]
|
||||
"values": [Vector3(0, 3.14159, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 3.14159, 0)]
|
||||
"values": [Vector3(0.244668, -0.229311, -0.30332)]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
|
|
@ -107,26 +107,26 @@ loop_mode = 1
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1.5),
|
||||
"transitions": PackedFloat32Array(-2, -2),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.244668, -0.229311, -0.30332), Vector3(0.244668, -0.26057, -0.30332)]
|
||||
"values": [Vector3(0, 3.14159, 0), Vector3(0.114371, 3.14159, -1.73453e-08)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 1.5),
|
||||
"transitions": PackedFloat32Array(-2, -2),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 3.14159, 0), Vector3(0.114371, 3.14159, -1.73453e-08)]
|
||||
"values": [Vector3(0.244668, -0.229311, -0.30332), Vector3(0.244668, -0.26057, -0.30332)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_p84l0"]
|
||||
|
|
@ -134,26 +134,26 @@ resource_name = "shoot"
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(0.5, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.244668, -0.204488, -0.268482), Vector3(0.244668, -0.229311, -0.30332)]
|
||||
"values": [Vector3(-0.0584511, 3.14159, 8.83593e-09), Vector3(0, 3.14159, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(0.5, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(-0.0584511, 3.14159, 8.83593e-09), Vector3(0, 3.14159, 0)]
|
||||
"values": [Vector3(0.244668, -0.204488, -0.268482), Vector3(0.244668, -0.229311, -0.30332)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hg307"]
|
||||
|
|
@ -244,9 +244,9 @@ near = 0.1
|
|||
|
||||
[node name="Inventory" type="Node3D" parent="SpringArm3D"]
|
||||
|
||||
[node name="SpaceGun" parent="SpringArm3D/Inventory" instance=ExtResource("4_lhn5w")]
|
||||
[node name="SpaceGun" parent="SpringArm3D/Inventory" instance=ExtResource("4_rm831")]
|
||||
transform = Transform3D(-1, 0, 2.53518e-06, 0, 1, 0, -2.53518e-06, 0, -1, 0.244668, -0.229311, -0.30332)
|
||||
PROJECTILE = ExtResource("5_lvaut")
|
||||
PROJECTILE = ExtResource("5_o1jib")
|
||||
|
||||
[node name="SpineIKTarget" type="Node3D" parent="SpringArm3D"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
|
|
|||
BIN
entities/weapons/space_gun/assets/SpaceGun.glb
Normal file
BIN
entities/weapons/space_gun/assets/SpaceGun.glb
Normal file
Binary file not shown.
BIN
entities/weapons/space_gun/assets/albedo.png
Normal file
BIN
entities/weapons/space_gun/assets/albedo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 364 KiB |
3
entities/weapons/space_gun/assets/material.tres
Normal file
3
entities/weapons/space_gun/assets/material.tres
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[gd_resource type="ShaderMaterial" format=3 uid="uid://de6t4olk7hrs1"]
|
||||
|
||||
[resource]
|
||||
BIN
entities/weapons/space_gun/assets/textures/albedo0.png
Normal file
BIN
entities/weapons/space_gun/assets/textures/albedo0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 364 KiB |
50
entities/weapons/space_gun/projectile.gd
Normal file
50
entities/weapons/space_gun/projectile.gd
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name Projectile extends Node3D
|
||||
|
||||
@export_category("Parameters")
|
||||
@export var EXPLOSION : PackedScene
|
||||
@export var speed : float = 78.4 # m/s
|
||||
@export var lifespan : float = 5.0 # in seconds
|
||||
|
||||
@onready var shape_cast = $ShapeCast3D
|
||||
@onready var game = get_tree().get_current_scene()
|
||||
|
||||
var velocity : Vector3 = Vector3.ZERO
|
||||
|
||||
func _ready():
|
||||
var lifespan_timer = Timer.new()
|
||||
lifespan_timer.wait_time = lifespan
|
||||
lifespan_timer.one_shot = true
|
||||
lifespan_timer.autostart = true
|
||||
lifespan_timer.timeout.connect(self_destruct)
|
||||
add_child(lifespan_timer)
|
||||
|
||||
func self_destruct():
|
||||
explode(position)
|
||||
|
||||
func explode(spawn_location):
|
||||
var spawned_explosion = EXPLOSION.instantiate()
|
||||
spawned_explosion.position = spawn_location
|
||||
game.add_child(spawned_explosion)
|
||||
queue_free()
|
||||
|
||||
func _physics_process(delta):
|
||||
var previous_position = global_position
|
||||
global_position += velocity * delta
|
||||
shape_cast.target_position = to_local(previous_position)
|
||||
if shape_cast.is_colliding():
|
||||
var contact_point = shape_cast.collision_result[0].point
|
||||
explode(contact_point)
|
||||
49
entities/weapons/space_gun/projectile.tscn
Normal file
49
entities/weapons/space_gun/projectile.tscn
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://dn1tcakam5egs"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile.gd" id="1_4j1dp"]
|
||||
[ext_resource type="PackedScene" uid="uid://8atq41j7wd55" path="res://entities/weapons/space_gun/projectile_explosion.tscn" id="2_llml6"]
|
||||
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile_trail.gd" id="3_ygqbh"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4a265"]
|
||||
transparency = 1
|
||||
blend_mode = 1
|
||||
cull_mode = 2
|
||||
shading_mode = 0
|
||||
vertex_color_use_as_albedo = true
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_o6j55"]
|
||||
albedo_color = Color(0, 0.498039, 0.854902, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(0.482353, 0.65098, 1, 1)
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_umtte"]
|
||||
radius = 0.15
|
||||
|
||||
[node name="Projectile" type="Node3D"]
|
||||
script = ExtResource("1_4j1dp")
|
||||
EXPLOSION = ExtResource("2_llml6")
|
||||
|
||||
[node name="Trail3D" type="MeshInstance3D" parent="."]
|
||||
material_override = SubResource("StandardMaterial3D_4a265")
|
||||
script = ExtResource("3_ygqbh")
|
||||
_from_width = 0.15
|
||||
_scale_acceleration = 0.5
|
||||
_lifespan = 0.25
|
||||
_start_color = Color(0, 0.498039, 0.854902, 1)
|
||||
_end_color = Color(1, 1, 1, 0)
|
||||
|
||||
[node name="Mesh" type="CSGSphere3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.2, 0, 0, 0, 1, 0, 0, 0)
|
||||
radius = 0.15
|
||||
radial_segments = 24
|
||||
rings = 8
|
||||
material = SubResource("StandardMaterial3D_o6j55")
|
||||
|
||||
[node name="ShapeCast3D" type="ShapeCast3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.2, 0, 0, 0, 1, 0, 0, 0)
|
||||
shape = SubResource("SphereShape3D_umtte")
|
||||
target_position = Vector3(0, 0, 0)
|
||||
margin = 0.1
|
||||
max_results = 1
|
||||
collision_mask = 2147483649
|
||||
debug_shape_custom_color = Color(1, 0, 0, 1)
|
||||
23
entities/weapons/space_gun/projectile_explosion.gd
Normal file
23
entities/weapons/space_gun/projectile_explosion.gd
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends Node3D
|
||||
|
||||
@onready var fire = $Fire
|
||||
@onready var explosive_damage : ExplosiveDamageComponent = $ExplosiveDamageComponent
|
||||
var explosion_effect_pending : bool = false
|
||||
|
||||
func _ready():
|
||||
fire.emitting = true
|
||||
fire.finished.connect(func(): queue_free())
|
||||
48
entities/weapons/space_gun/projectile_explosion.tscn
Normal file
48
entities/weapons/space_gun/projectile_explosion.tscn
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://8atq41j7wd55"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile_explosion.gd" id="1_fp5td"]
|
||||
[ext_resource type="PackedScene" uid="uid://ds1hekx1dq1bg" path="res://components/explosive_damage_component.tscn" id="2_d4sf4"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_rg204"]
|
||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="CurveTexture" id="CurveTexture_08dbu"]
|
||||
curve = SubResource("Curve_rg204")
|
||||
|
||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3mf41"]
|
||||
spread = 180.0
|
||||
initial_velocity_min = 12.0
|
||||
initial_velocity_max = 12.0
|
||||
scale_curve = SubResource("CurveTexture_08dbu")
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_wpu51"]
|
||||
albedo_color = Color(0.819608, 0, 0, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(1, 0.254902, 0.109804, 1)
|
||||
emission_energy_multiplier = 4.0
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_k3pnh"]
|
||||
material = SubResource("StandardMaterial3D_wpu51")
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_mlo2k"]
|
||||
radius = 5.0
|
||||
|
||||
[node name="ProjectileExplosion" type="Node3D"]
|
||||
script = ExtResource("1_fp5td")
|
||||
|
||||
[node name="Fire" type="GPUParticles3D" parent="."]
|
||||
emitting = false
|
||||
amount = 24
|
||||
lifetime = 0.5
|
||||
one_shot = true
|
||||
explosiveness = 1.0
|
||||
fixed_fps = 60
|
||||
process_material = SubResource("ParticleProcessMaterial_3mf41")
|
||||
draw_pass_1 = SubResource("SphereMesh_k3pnh")
|
||||
|
||||
[node name="ExplosiveDamageComponent" parent="." instance=ExtResource("2_d4sf4")]
|
||||
damage = 35
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="ExplosiveDamageComponent"]
|
||||
shape = SubResource("SphereShape3D_mlo2k")
|
||||
94
entities/weapons/space_gun/projectile_trail.gd
Normal file
94
entities/weapons/space_gun/projectile_trail.gd
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name Trail3D extends MeshInstance3D
|
||||
|
||||
var _points = [] # 3D points of trail
|
||||
var _widths = [] # Calculated widths of trail
|
||||
var _lifespans = [] # Trail point lifespans
|
||||
|
||||
@export var _trail_enabled : bool = true # Is trail shown?
|
||||
|
||||
@export var _from_width : float = 0.5 # Starting width
|
||||
@export var _to_width : float = 0.0 # Ending width
|
||||
|
||||
@export_range(0.5, 1.5) var _scale_acceleration : float = 1.0 # Scaling speed
|
||||
|
||||
@export var _motion_delta : float = 0.1 # Smoothness of trail
|
||||
@export var _lifespan : float = 1.0 # Duration of trail
|
||||
|
||||
@export var _start_color : Color = Color(1.0, 1.0, 1.0, 1.0) # Start color
|
||||
@export var _end_color : Color = Color(1.0, 1.0, 1.0, 1.0) # End color
|
||||
|
||||
var _old_pos : Vector3 # Previous pos
|
||||
|
||||
func _append_point():
|
||||
_points.append(get_global_transform().origin)
|
||||
_widths.append([
|
||||
get_global_transform().basis.x * _from_width,
|
||||
get_global_transform().basis.x * _from_width - get_global_transform().basis.x * _to_width
|
||||
])
|
||||
_lifespans.append(0.0)
|
||||
|
||||
func _remove_point(i):
|
||||
_points.remove_at(i)
|
||||
_widths.remove_at(i)
|
||||
_lifespans.remove_at(i)
|
||||
|
||||
func _ready():
|
||||
_old_pos = get_global_transform().origin
|
||||
mesh = ImmediateMesh.new()
|
||||
|
||||
func _process(delta):
|
||||
if(_old_pos - get_global_transform().origin).length() > _motion_delta and _trail_enabled:
|
||||
_append_point() # Create new point
|
||||
_old_pos = get_global_transform().origin # Update previous position to current position coordinates
|
||||
|
||||
# Update the lifespan
|
||||
var p = 0
|
||||
var max_points = _points.size()
|
||||
while p < max_points:
|
||||
_lifespans[p] += delta
|
||||
if _lifespans[p] > _lifespan:
|
||||
_remove_point(p)
|
||||
p -= 1
|
||||
if (p < 0): p = 0
|
||||
|
||||
max_points = _points.size()
|
||||
p += 1
|
||||
|
||||
mesh.clear_surfaces()
|
||||
|
||||
# If less than 2 points, stop rendering trail
|
||||
if _points.size() < 2:
|
||||
return
|
||||
|
||||
# Render new mesh for each point
|
||||
mesh.surface_begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
|
||||
|
||||
for i in range(_points.size()):
|
||||
var t = float(i) / (_points.size() - 1.0)
|
||||
var curr_color = _start_color.lerp(_end_color, 1 - t)
|
||||
mesh.surface_set_color(curr_color)
|
||||
|
||||
var curr_width = _widths[i][0] - pow(1 - t, _scale_acceleration) * _widths[i][1]
|
||||
|
||||
var t0 = i / _points.size()
|
||||
var t1 = t
|
||||
|
||||
mesh.surface_set_uv(Vector2(t0, 0))
|
||||
mesh.surface_add_vertex(to_local(_points[i] + curr_width))
|
||||
mesh.surface_set_uv(Vector2(t1, 1))
|
||||
mesh.surface_add_vertex(to_local(_points[i] - curr_width))
|
||||
mesh.surface_end()
|
||||
47
entities/weapons/space_gun/space_gun.gd
Normal file
47
entities/weapons/space_gun/space_gun.gd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends Node3D
|
||||
class_name SpaceGun
|
||||
|
||||
@export var PROJECTILE : PackedScene
|
||||
|
||||
@onready var nozzle = $Nozzle
|
||||
@onready var inventory = get_parent()
|
||||
|
||||
enum WeaponState { WEAPON_READY, WEAPON_RELOADING }
|
||||
|
||||
var weapon_state : WeaponState = WeaponState.WEAPON_READY
|
||||
|
||||
const inheritance : float = .5 # ratio
|
||||
const reload_time : float = 1. # seconds
|
||||
|
||||
func can_fire():
|
||||
return weapon_state == WeaponState.WEAPON_READY
|
||||
|
||||
func fire_primary():
|
||||
if not can_fire():
|
||||
return
|
||||
|
||||
var projectile = PROJECTILE.instantiate()
|
||||
projectile.transform = nozzle.global_transform
|
||||
projectile.velocity = nozzle.global_basis.z.normalized() * projectile.speed
|
||||
var inheritance_factor = clamp(inheritance, 0., 1.)
|
||||
projectile.velocity += (inventory.owner.linear_velocity * inheritance_factor)
|
||||
inventory.owner.add_sibling(projectile)
|
||||
var collider = projectile.shape_cast
|
||||
collider.add_exception(inventory.owner)
|
||||
weapon_state = WeaponState.WEAPON_RELOADING
|
||||
await get_tree().create_timer(reload_time).timeout
|
||||
weapon_state = WeaponState.WEAPON_READY
|
||||
69
entities/weapons/space_gun/space_gun.tscn
Normal file
69
entities/weapons/space_gun/space_gun.tscn
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue