weapon swap working and array tracking bullet status
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=20 format=3 uid="uid://brl0bsqjl5dg3"]
|
||||
[gd_scene load_steps=22 format=3 uid="uid://brl0bsqjl5dg3"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c33b6ldlxxfro" path="res://assets/Models/mac10.blend" id="1_nb4p5"]
|
||||
[ext_resource type="Script" path="res://scripts/gun.gd" id="2_6i1l4"]
|
||||
@@ -310,17 +310,90 @@ tracks/5/keys = {
|
||||
[sub_resource type="Animation" id="Animation_tikvk"]
|
||||
resource_name = "sprint"
|
||||
|
||||
[sub_resource type="Animation" id="Animation_i5303"]
|
||||
resource_name = "swap_out"
|
||||
step = 0.01
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("mac10:position")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.25, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 0, 0), Vector3(-0.270935, -0.0610588, 0), Vector3(1.24557, 1.01031, 2.22439)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("mac10:rotation")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.25, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, -1.5708, 0), Vector3(-0.0758979, -1.23084, 0.21119), Vector3(-0.0713455, -1.36426, -2.36786)]
|
||||
}
|
||||
tracks/2/type = "method"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath(".")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(1),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"values": [{
|
||||
"args": [],
|
||||
"method": &"swapped_out"
|
||||
}]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_0sp0s"]
|
||||
resource_name = "swap_in"
|
||||
step = 0.01
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("mac10:position")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.6, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(1.24557, 1.01031, 2.22439), Vector3(-0.270935, -0.0610588, 0), Vector3(0, 0, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("mac10:rotation")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.6, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(-0.0713455, -1.36426, -2.36786), Vector3(-0.0758979, -1.23084, 0.21119), Vector3(0, -1.5708, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_vkrtt"]
|
||||
_data = {
|
||||
"empty": SubResource("Animation_u008m"),
|
||||
"inspect": SubResource("Animation_cifop"),
|
||||
"reload": SubResource("Animation_svhrs"),
|
||||
"shoot": SubResource("Animation_bsc1a"),
|
||||
"sprint": SubResource("Animation_tikvk")
|
||||
"sprint": SubResource("Animation_tikvk"),
|
||||
"swap_in": SubResource("Animation_0sp0s"),
|
||||
"swap_out": SubResource("Animation_i5303")
|
||||
}
|
||||
|
||||
[node name="mac10" node_paths=PackedStringArray("flare_light", "anim_player", "barrel_raycast", "casing_ejector", "mag_ejector", "audio_fire", "audio_empty", "audio_reload") instance=ExtResource("1_nb4p5")]
|
||||
script = ExtResource("2_6i1l4")
|
||||
gun_name = "Mac 10"
|
||||
max_ammo = 30
|
||||
random_spread_amt = 1.5
|
||||
fire_pitch_scale_amt = 0.1
|
||||
@@ -338,7 +411,7 @@ audio_empty = NodePath("Audio/Empty")
|
||||
audio_reload = NodePath("Audio/Reload")
|
||||
|
||||
[node name="mac10" parent="." index="0"]
|
||||
transform = Transform3D(-1.92883e-06, 0, -0.532829, 0, 0.532828, 0, 0.532828, 0, -1.92884e-06, 0, 0, 0)
|
||||
transform = Transform3D(0.00110078, 0.000233951, -0.532828, 0.00152579, 0.532826, 0.000237103, 0.532825, -0.00152628, 0.00110011, -0.00253865, -0.0010342, -0.00140877)
|
||||
|
||||
[node name="SpotLight3D" type="SpotLight3D" parent="mac10" index="0"]
|
||||
transform = Transform3D(-6.79394e-06, 0, 1.87678, 0, 1.87678, 0, -1.87677, 0, -6.79392e-06, -1.63231, 0, 5.90892e-06)
|
||||
@@ -377,7 +450,7 @@ transform = Transform3D(-0.00171201, 5.61171e-05, 1.87678, 0.567942, 1.78878, 0.
|
||||
target_position = Vector3(1, 0, 0)
|
||||
|
||||
[node name="Trigger" parent="mac10" index="7"]
|
||||
transform = Transform3D(0.962182, -0.272406, 6.11661e-07, 0.272406, 0.962182, -1.62236e-06, -1.4659e-07, 1.72762e-06, 1, -0.13807, -0.230628, 0.00528617)
|
||||
transform = Transform3D(0.978226, 0.207541, 0, -0.207541, 0.978226, 0, 0, 0, 1, -0.13807, -0.230628, 0.00528617)
|
||||
|
||||
[node name="GunAnims" type="AnimationPlayer" parent="." index="1"]
|
||||
libraries = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=17 format=3 uid="uid://dslxb3psx30vp"]
|
||||
[gd_scene load_steps=19 format=3 uid="uid://dslxb3psx30vp"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://svrb3n31mkag" path="res://assets/Models/gun.blend" id="1_frekg"]
|
||||
[ext_resource type="Script" path="res://scripts/gun.gd" id="2_63tea"]
|
||||
@@ -195,18 +195,89 @@ tracks/2/keys = {
|
||||
[sub_resource type="Animation" id="Animation_tikvk"]
|
||||
resource_name = "sprint"
|
||||
|
||||
[sub_resource type="Animation" id="Animation_lleyf"]
|
||||
resource_name = "swap_out"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("gun:position")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.4, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, -0.000397999, 0), Vector3(-0.274662, -0.000397999, 0.0729132), Vector3(1.44543, 1.00681, 2.10684)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("gun:rotation")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.4, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, -1.5708, 0), Vector3(-0.289219, -1.03888, -0.16629), Vector3(-0.221353, -1.10575, -2.02639)]
|
||||
}
|
||||
tracks/2/type = "method"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath(".")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(1),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"values": [{
|
||||
"args": [],
|
||||
"method": &"swapped_out"
|
||||
}]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_7422e"]
|
||||
resource_name = "swap_in"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("gun:position")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.7, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(1.44543, 1.00681, 2.10684), Vector3(-0.274662, -0.000397999, 0.0729132), Vector3(0, -0.000397999, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("gun:rotation")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.7, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(-0.221353, -1.10575, -2.02639), Vector3(-0.289219, -1.03888, -0.16629), Vector3(0, -1.5708, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_vkrtt"]
|
||||
_data = {
|
||||
"empty": SubResource("Animation_u008m"),
|
||||
"inspect": SubResource("Animation_cifop"),
|
||||
"reload": SubResource("Animation_svhrs"),
|
||||
"shoot": SubResource("Animation_bsc1a"),
|
||||
"sprint": SubResource("Animation_tikvk")
|
||||
"sprint": SubResource("Animation_tikvk"),
|
||||
"swap_in": SubResource("Animation_7422e"),
|
||||
"swap_out": SubResource("Animation_lleyf")
|
||||
}
|
||||
|
||||
[node name="Pistol" node_paths=PackedStringArray("flare_light", "anim_player", "barrel_raycast", "casing_ejector", "mag_ejector", "audio_fire", "audio_empty", "audio_reload") instance=ExtResource("1_frekg")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0145504, -0.0460228)
|
||||
script = ExtResource("2_63tea")
|
||||
gun_name = "Dumb Pistol"
|
||||
fire_mode = 2
|
||||
flare_light = NodePath("SpotLight3D")
|
||||
bullet = ExtResource("3_4pvsf")
|
||||
|
||||
@@ -26,8 +26,8 @@ shadow_color = Color(0, 0, 0, 1)
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_nfpjw"]
|
||||
size = Vector3(3, 3, 3)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_gnkxs"]
|
||||
size = Vector3(11.7881, 6, 11)
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_xfie3"]
|
||||
radius = 6.0
|
||||
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_holder") groups=["player"]]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.11359, 0)
|
||||
@@ -120,8 +120,8 @@ collision_layer = 0
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="pick_up_magnet"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.457243, -3.73375)
|
||||
shape = SubResource("BoxShape3D_gnkxs")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.89866, 0, 0)
|
||||
shape = SubResource("SphereShape3D_xfie3")
|
||||
|
||||
[node name="Audio" type="Node" parent="."]
|
||||
|
||||
|
||||
@@ -413,6 +413,7 @@ gun_2 = ExtResource("3_rky7g")
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_f87c2")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.0295, 1.4435, 21.1166)
|
||||
AUDIO = false
|
||||
weapon_sway_amount = 0.05
|
||||
weapon_rotation_amount = 0.05
|
||||
|
||||
|
||||
@@ -18,4 +18,4 @@ func _ready():
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
text = "Ammo: " + str(level_control.ammo_current[gun_index]) +" " + str(level_control.ammo_reserve[gun_index])
|
||||
text = str(player.gun.gun_name) + "\n Ammo: " + str(level_control.ammo_current[level_control.current_gun_index]) +" " + str(level_control.ammo_reserve[level_control.current_gun_index])
|
||||
|
||||
@@ -16,22 +16,36 @@ func _ready():
|
||||
held_guns = [gun_1,gun_2]
|
||||
var instance_gun = held_guns[0].instantiate()
|
||||
var instance_gun_2 = held_guns[1].instantiate()
|
||||
|
||||
#set up ammo for starting guns
|
||||
ammo_current[1] = instance_gun_2.max_ammo
|
||||
ammo_reserve[1] = instance_gun_2.max_ammo * instance_gun_2.start_mags
|
||||
|
||||
ammo_current[0] = instance_gun.max_ammo
|
||||
ammo_reserve[0] = instance_gun.max_ammo * instance_gun.start_mags
|
||||
print(ammo_current)
|
||||
print(ammo_reserve)
|
||||
#spawn first gun
|
||||
current_gun_index = 0
|
||||
gun_spawn(0)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func gun_spawn(index):
|
||||
#loop around if scrolling past available guns
|
||||
if index > held_guns.size() - 1:
|
||||
index = 0
|
||||
elif index < 0:
|
||||
index = held_guns.size() - 1
|
||||
|
||||
current_gun_index = index
|
||||
|
||||
var instance_gun = held_guns[index].instantiate()
|
||||
instance_gun.global_transform.origin = player.weapon_spawner.position
|
||||
player.gun = instance_gun
|
||||
player.def_weapon_holder_pos = player.weapon_holder.position
|
||||
player.ammo = player.gun.max_ammo
|
||||
player.ammo_reserve = player.gun.max_ammo * player.gun.start_mags
|
||||
player.gun_fire_pitch_starting = player.gun.audio_fire.pitch_scale
|
||||
instance_gun.gun_index = 0
|
||||
instance_gun.gun_index = index
|
||||
instance_gun.anim_player.play("swap_in")
|
||||
player.weapon_holder.add_child(instance_gun)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
@@ -7,6 +7,7 @@ var cycle_count_start
|
||||
var cycle_count
|
||||
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var recoil_amount = .2
|
||||
@export var max_ammo = 15
|
||||
@@ -134,3 +135,6 @@ func spawn_mag():
|
||||
instance_mag.position = mag_ejector.global_position
|
||||
instance_mag.transform.basis = mag_ejector.global_transform.basis
|
||||
get_tree().get_root().add_child(instance_mag)
|
||||
|
||||
func swapped_out():
|
||||
queue_free()
|
||||
|
||||
@@ -180,29 +180,13 @@ func _physics_process(delta):
|
||||
gun_folded = false
|
||||
|
||||
#Weapon Swap Up
|
||||
if Input.is_action_just_pressed("scroll_up"):
|
||||
gun.queue_free()
|
||||
var instance_gun = level_control.gun_2.instantiate()
|
||||
instance_gun.global_transform.origin = weapon_spawner.position
|
||||
gun = instance_gun
|
||||
def_weapon_holder_pos = weapon_holder.position
|
||||
ammo = gun.max_ammo
|
||||
ammo_reserve = gun.max_ammo * gun.start_mags
|
||||
bullet_damage = gun.bullet_damage
|
||||
gun_fire_pitch_starting = gun.audio_fire.pitch_scale
|
||||
weapon_holder.add_child(instance_gun)
|
||||
if Input.is_action_just_pressed("scroll_up") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index + 1)
|
||||
#Weapon Swap Down
|
||||
if Input.is_action_just_pressed("scroll_down"):
|
||||
gun.queue_free()
|
||||
var instance_gun = level_control.gun_1.instantiate()
|
||||
instance_gun.global_transform.origin = weapon_spawner.position
|
||||
gun = instance_gun
|
||||
def_weapon_holder_pos = weapon_holder.position
|
||||
ammo = gun.max_ammo
|
||||
ammo_reserve = gun.max_ammo * gun.start_mags
|
||||
bullet_damage = gun.bullet_damage
|
||||
gun_fire_pitch_starting = gun.audio_fire.pitch_scale
|
||||
weapon_holder.add_child(instance_gun)
|
||||
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index - 1)
|
||||
|
||||
move_and_slide()
|
||||
weapon_tilt(input_dir.x, delta)
|
||||
@@ -229,7 +213,7 @@ func _on_pick_up_detection_body_entered(body):
|
||||
pickupmsg = pickup_announce.instantiate()
|
||||
pickupmsg.pickuptext = "ammo"
|
||||
get_parent().add_child(pickupmsg)
|
||||
ammo_reserve += int((body.rand_amt/100) * gun.max_ammo)
|
||||
level_control.ammo_reserve[level_control.current_gun_index] += int((body.rand_amt/100) * gun.max_ammo)
|
||||
picked_up = true
|
||||
picked_up_text = "ammo"
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
|
||||
Reference in New Issue
Block a user