Files
fps_project_1/scripts/melee_weapon.gd
2025-01-27 19:52:52 -06:00

70 lines
1.8 KiB
GDScript

extends Node3D
@export_group("Gun Feel")
@export var gun_name : String
@export var gun_icon : Texture2D
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket","Melee") var ammo_type: int
@export var collision_shape : Node
@export var fov_zoom_amt = 0
@export var ads : bool = false
@export var recoil_amount : Vector3 = Vector3(0,.2,.2)
@export var bullet_damage = 1
@export_group("Gun Assets")
@export_subgroup("Main Assets")
@export var anim_player : Node
@export_subgroup("Audio Clips")
@export var audio_fire : Node
@onready var player = get_tree().current_scene.player
@onready var level_control = get_tree().current_scene
@onready var muzzle_smoke = preload("res://assets/muzzle_smoke.tscn")
var max_ammo = 0
var start_mags = 0
var start_position
var start_rotation
var random_spread_start
var cycle_count_start
var cycle_count
var rng = RandomNumberGenerator.new()
var gun_index
# Called when the node enters the scene tree for the first time.
func _ready():
collision_shape.disabled = true
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
func shoot(delta):
if !anim_player.is_playing():
#audio and anims
anim_player.play("shoot")
vibration()
player.recoil.add_recoil(Vector3(0,recoil_amount.y,recoil_amount.z),10,10)
player.recoil.add_gun_recoil(recoil_amount.x)
SignalBus.emit_signal("shot_fired")
func collider_enable():
collision_shape.disabled = false
func collider_disable():
collision_shape.disabled = true
func swapped_out():
queue_free()
func vibration():
Input.start_joy_vibration(0,.1,.5,.1)
func _on_area_3d_body_entered(body: Node3D) -> void:
if body.has_method("hit"):
body.hit(bullet_damage)
if body.is_in_group("breakable"):
var current_velocity = transform.basis * Vector3(0,0,-1)
body.breaking(current_velocity)