instancing start gun and assigned ammo to array

This commit is contained in:
derek
2024-07-15 12:16:54 -05:00
parent a18fb55e8d
commit 4da08f3df5
4 changed files with 39 additions and 19 deletions

View File

@@ -27,7 +27,7 @@ shadow_color = Color(0, 0, 0, 1)
size = Vector3(3, 3, 3)
[sub_resource type="BoxShape3D" id="BoxShape3D_gnkxs"]
size = Vector3(10, 5.48804, 10)
size = Vector3(11.7881, 6, 11)
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_holder", "gun") groups=["player"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.11359, 0)
@@ -85,7 +85,6 @@ padding_amount = 0.025
[node name="GunRay" type="RayCast3D" parent="Head/Camera3D" groups=["gun_ray"]]
transform = Transform3D(0.977933, 0, -0.208919, 0, 1, 7.45058e-09, 0.208919, 0, 0.977933, 0, -0.197421, -0.129669)
target_position = Vector3(0, 0, -1.5)
collision_mask = 3
[node name="AudioListener3D" type="AudioListener3D" parent="Head/Camera3D"]
transform = Transform3D(1, 0, 0, 0, 0.992332, 0.123601, 0, -0.123601, 0.992332, 0, -0.921646, -0.000722691)
@@ -122,7 +121,7 @@ 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.713223, -3.23375)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.457243, -3.73375)
shape = SubResource("BoxShape3D_gnkxs")
[node name="Audio" type="Node" parent="."]

View File

@@ -1,5 +1,6 @@
extends Node3D
<<<<<<< Updated upstream
var current_weapon = null
var weapon_stack = []
var weapon_indicator = 0
@@ -7,10 +8,38 @@ var next_weapon : String
var weapon_list = {}
@export var weapon_resources : Array[weapon_resource]
=======
@export var player : Node
@export var gun_1 : Resource
@export var gun_2 : Resource
var held_guns = []
var ammo_current = [0,0]
var ammo_reserve = [0,0]
var guns_dict = {}
var current_gun_index
>>>>>>> Stashed changes
# Called when the node enters the scene tree for the first time.
func _ready():
pass
held_guns = [gun_1,gun_2]
var instance_gun = held_guns[0].instantiate()
var instance_gun_2 = held_guns[1].instantiate()
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)
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
current_gun_index = 0
player.weapon_holder.add_child(instance_gun)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):

View File

@@ -36,13 +36,16 @@ var cycle_count
@onready var player = $"../../../../"
var rng = RandomNumberGenerator.new()
var level_control
# Called when the node enters the scene tree for the first time.
func _ready():
start_position = self.position
start_rotation = self.rotation
random_spread_start = random_spread_amt
level_control = get_tree().get_root()
if fire_mode == 0:
cycle_count = 1
cycle_count_start = 1
@@ -103,7 +106,7 @@ func shoot(player,delta):
instance_casing.transform.basis = casing_ejector.global_transform.basis
get_tree().get_root().add_child(instance_casing)
if fire_mode == 1 or fire_mode == 2:
if fire_mode != 0:
cycle_count -= 1
elif !anim_player.is_playing() and cycle_count != 0:

View File

@@ -72,17 +72,6 @@ func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
start_sensitivity = SENSITIVITY
#Set up gun variables
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)
#turn off audio if unchecked in player
if AUDIO == false:
@@ -269,8 +258,8 @@ func weapon_tilt(input_x, delta):
func weapon_sway(delta):
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_rotation_amount, 1 * delta)
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_rotation_amount, 1 * delta)
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_rotation_amount, 5 * delta)
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_rotation_amount, 5 * delta)
#crosshair.position.x = lerp(crosshair.position.x, mouse_input.x * 100, 2 * delta)