moved key gun functions into gun script. small glitch in reload animation that I havent diagnosed yet

This commit is contained in:
Derek
2024-07-14 19:04:53 -05:00
parent db3b4fdbdc
commit b9001901df
6 changed files with 691 additions and 42 deletions

View File

@@ -212,6 +212,20 @@ tracks/6/keys = {
"update": 0, "update": 0,
"values": [0.0] "values": [0.0]
} }
tracks/7/type = "method"
tracks/7/imported = false
tracks/7/enabled = true
tracks/7/path = NodePath(".")
tracks/7/interp = 1
tracks/7/loop_wrap = true
tracks/7/keys = {
"times": PackedFloat32Array(0.28),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"spawn_mag"
}]
}
[sub_resource type="Animation" id="Animation_bsc1a"] [sub_resource type="Animation" id="Animation_bsc1a"]
resource_name = "shoot" resource_name = "shoot"
@@ -305,7 +319,7 @@ _data = {
[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")] [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") script = ExtResource("2_6i1l4")
max_ammo = 30 max_ammo = 30
start_mags = 4 start_mags = 100
random_spread_amt = 1.5 random_spread_amt = 1.5
flare_light = NodePath("mac10/SpotLight3D") flare_light = NodePath("mac10/SpotLight3D")
bullet = ExtResource("3_pyl20") bullet = ExtResource("3_pyl20")

View File

@@ -11,6 +11,7 @@ damping = 0.1
wet = 0.1 wet = 0.1
[resource] [resource]
bus/0/volume_db = -80.0
bus/0/effect/0/effect = SubResource("AudioEffectPitchShift_qiw0e") bus/0/effect/0/effect = SubResource("AudioEffectPitchShift_qiw0e")
bus/0/effect/0/enabled = false bus/0/effect/0/enabled = false
bus/1/name = &"SFX" bus/1/name = &"SFX"

637
scenes/tesDD33.tmp Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -57,7 +57,7 @@ func _on_gun_anims_animation_finished(anim_name):
player.ammo_reserve -= player.ammo_reserve player.ammo_reserve -= player.ammo_reserve
player.reloading = false player.reloading = false
func shoot(player,bullet_ray,delta): func shoot(player,delta):
if player.ammo > 0: if player.ammo > 0:
if !anim_player.is_playing(): if !anim_player.is_playing():
player.ammo -= 1 player.ammo -= 1
@@ -69,34 +69,43 @@ func shoot(player,bullet_ray,delta):
anim_player.play("shoot") anim_player.play("shoot")
# shoot real bullet from camera # shoot real bullet from camera
var instance_bullet = bullet.instantiate()
instance_bullet.position = player.bullet_ray.global_position
#shoot bullet from real gun if gun is folded up
if player.gun_folded == false: if player.gun_folded == false:
var instance_bullet = bullet.instantiate() instance_bullet.transform.basis = player.bullet_ray.global_transform.basis
instance_bullet.position = bullet_ray.global_position
instance_bullet.transform.basis = bullet_ray.global_transform.basis
instance_bullet.bullet_speed = bullet_speed
instance_bullet.bullet_drop = bullet_drop
instance_bullet.random_spread_amt = random_spread_amt
instance_bullet.gun = self
print("bullet coords: " + str(instance_bullet.position))
print("bullet transform: " + str(instance_bullet.transform.basis))
get_parent().add_child(instance_bullet)
else: else:
var instance_bullet = bullet.instantiate()
instance_bullet.position = barrel_raycast.global_position
instance_bullet.transform.basis = barrel_raycast.global_transform.basis instance_bullet.transform.basis = barrel_raycast.global_transform.basis
instance_bullet.bullet_speed = bullet_speed instance_bullet.bullet_speed = bullet_speed
instance_bullet.bullet_drop = bullet_drop instance_bullet.bullet_drop = bullet_drop
instance_bullet.random_spread_amt = random_spread_amt instance_bullet.random_spread_amt = random_spread_amt
instance_bullet.gun = self instance_bullet.gun = self
get_parent().add_child(instance_bullet) get_tree().get_root().add_child(instance_bullet)
# Casing transform # Casing transform
var instance_casing = casing.instantiate() var instance_casing = casing.instantiate()
instance_casing.position = casing_ejector.global_position instance_casing.position = casing_ejector.global_position
instance_casing.transform.basis = casing_ejector.global_transform.basis instance_casing.transform.basis = casing_ejector.global_transform.basis
get_tree().get_root().add_child(instance_casing)
get_parent().add_child(instance_casing)
elif !anim_player.is_playing(): elif !anim_player.is_playing():
anim_player.play("empty") anim_player.play("empty")
audio_empty.play() audio_empty.play()
func reload(player,delta):
if player.ammo < max_ammo and player.reloading == false and player.ammo_reserve > 0:
player.reloading = true
anim_player.play("reload")
audio_reload.play()
if anim_player.is_playing() and anim_player.current_animation == "reload":
if player.ammo == 0:
player.ammo = 0
else:
player.ammo = 1
func spawn_mag():
var instance_mag = mag.instantiate()
instance_mag.position = mag_ejector.global_position
instance_mag.transform.basis = mag_ejector.global_transform.basis
get_tree().get_root().add_child(instance_mag)

View File

@@ -152,26 +152,14 @@ func _physics_process(delta):
# Reloading # Reloading
if Input.is_action_just_pressed("reload"): if Input.is_action_just_pressed("reload"):
if ammo < gun.max_ammo and reloading == false and ammo_reserve > 0: gun.reload(self,delta)
reloading = true
gun.anim_player.play("reload")
gun.audio_reload.play()
instance_mag = gun.mag.instantiate()
await get_tree().create_timer(.28).timeout
instance_mag.position = gun.mag_ejector.global_position
instance_mag.transform.basis = gun.mag_ejector.global_transform.basis
get_parent().add_child(instance_mag)
if gun.anim_player.is_playing() and gun.anim_player.current_animation == "reload":
if ammo == 0:
ammo = 0
else:
ammo = 1
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing(): if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
gun.anim_player.play("inspect") gun.anim_player.play("inspect")
# Shooting # Shooting
if Input.is_action_pressed("shoot"): if Input.is_action_pressed("shoot"):
gun.shoot(self,bullet_ray,delta) gun.shoot(self,delta)
@@ -239,8 +227,8 @@ func weapon_tilt(input_x, delta):
func weapon_sway(delta): func weapon_sway(delta):
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * 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, 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, 10 * delta) weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_rotation_amount, 1 * delta)
#crosshair.position.x = lerp(crosshair.position.x, mouse_input.x * 100, 2 * delta) #crosshair.position.x = lerp(crosshair.position.x, mouse_input.x * 100, 2 * delta)