Added fire mode select on gun script

This commit is contained in:
Derek
2024-07-14 20:06:00 -05:00
parent 582e03202a
commit 6fedc3e3c5
18 changed files with 382 additions and 31 deletions

23
scripts/bullet3.gd Normal file
View File

@@ -0,0 +1,23 @@
extends AnimatableBody3D
const SPEED = 30.0
@onready var mesh = $MeshInstance3D
@onready var ray = $RayCast3D
@onready var particles = $GPUParticles3D
# Called when the node enters the scene tree for the first time.
func _ready():
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

@@ -3,8 +3,11 @@ extends Node3D
var start_position
var start_rotation
var random_spread_start
var cycle_count_start
var cycle_count
@export_group("Gun Feel")
@export_enum("Auto", "Single", "Burst") var fire_mode: int
@export var recoil_amount = .2
@export var max_ammo = 15
@export var start_mags = 3
@@ -13,6 +16,7 @@ var random_spread_start
@export var bullet_speed = 150
@export var bullet_drop = .3
@export var random_spread_amt = 1.0
@export var fire_pitch_scale_amt = .2
@export_group("Gun Assets")
@export_subgroup("Main Assets")
@export var flare_light : Node
@@ -38,6 +42,16 @@ func _ready():
start_position = self.position
start_rotation = self.rotation
random_spread_start = random_spread_amt
if fire_mode == 0:
cycle_count = 1
cycle_count_start = 1
elif fire_mode == 1:
cycle_count = 1
cycle_count_start = 1
elif fire_mode == 2:
cycle_count = 3
cycle_count_start = 3
@@ -58,18 +72,18 @@ func _on_gun_anims_animation_finished(anim_name):
player.reloading = false
func shoot(player,delta):
if player.ammo > 0:
if player.ammo > 0 and cycle_count > 0:
if !anim_player.is_playing():
player.ammo -= 1
#RECOIL --- fix later to happen over a period of time
player.camera.rotation.x = clamp(lerp(player.camera.rotation.x, player.camera.rotation.x + recoil_amount, delta * 10), deg_to_rad(-90), deg_to_rad(60))
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
audio_fire.pitch_scale = 1 + rng.randf_range(-.2,.2)
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
audio_fire.play()
anim_player.play("shoot")
# shoot real bullet from camera
# instance bullet
var instance_bullet = bullet.instantiate()
instance_bullet.position = player.bullet_ray.global_position
#shoot bullet from real gun if gun is folded up
@@ -88,8 +102,11 @@ func shoot(player,delta):
instance_casing.position = casing_ejector.global_position
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:
cycle_count -= 1
elif !anim_player.is_playing():
elif !anim_player.is_playing() and cycle_count != 0:
anim_player.play("empty")
audio_empty.play()

View File

@@ -8,6 +8,8 @@ var mouse_input : Vector2
var rng = RandomNumberGenerator.new()
@export_group("Game Settings")
@export var AUDIO = true
@export_group("Player Movement")
@export var WALK_SPEED = 7.0
@export var SPRINT_SPEED = 15.0
@@ -73,6 +75,10 @@ func _ready():
bullet_damage = gun.bullet_damage
start_sensitivity = SENSITIVITY
gun_fire_pitch_starting = gun.audio_fire.pitch_scale
#turn off audio if unchecked in player
if AUDIO == false:
AudioServer.set_bus_volume_db(0,-80)
func _unhandled_input(event):
if event is InputEventMouseMotion:
@@ -157,11 +163,12 @@ func _physics_process(delta):
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
gun.anim_player.play("inspect")
# Shooting
# Shooting & fire modes
if Input.is_action_pressed("shoot"):
gun.shoot(self,delta)
if Input.is_action_just_released("shoot"):
gun.cycle_count = gun.cycle_count_start
# Gun folding out of the way
if gun_ray.is_colliding() and !gun_ray.get_collider().is_in_group("player"):