got the script closer but also broke it harder
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
extends Node3D
|
||||
|
||||
class_name weapon
|
||||
|
||||
@export var weapon_info : weapon_resource
|
||||
@export var anim_player : AnimationPlayer
|
||||
@@ -20,7 +20,10 @@ extends Node3D
|
||||
|
||||
@onready var player = get_tree().current_scene.player
|
||||
|
||||
var revolver_chamber_rot_amt
|
||||
# Revolver vars
|
||||
var revolver_chamber_rot_amt = 0
|
||||
var casings_chamber_last
|
||||
|
||||
var start_position
|
||||
var start_rotation
|
||||
var cycle_count_start
|
||||
@@ -31,6 +34,9 @@ var gun_index
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
||||
if weapon_info.weapon_type == 0:
|
||||
casings_chamber_last = weapon_info.max_ammo
|
||||
|
||||
if weapon_info.fire_mode == 0:
|
||||
cycle_count = 1
|
||||
cycle_count_start = 1
|
||||
@@ -55,9 +61,11 @@ func reload_finished():
|
||||
if GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] >= weapon_info.max_ammo:
|
||||
GameGlobals.gun_ammo[weapon_info.gun_name] += weapon_info.max_ammo
|
||||
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= weapon_info.max_ammo
|
||||
casings_chamber_last = weapon_info.max_ammo
|
||||
else:
|
||||
GameGlobals.gun_ammo[weapon_info.gun_name] += GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
|
||||
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
|
||||
casings_chamber_last = GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
|
||||
|
||||
func shoot(delta):
|
||||
if weapon_info.weapon_type == 0:
|
||||
@@ -68,8 +76,6 @@ func shoot(delta):
|
||||
audio_fire.play()
|
||||
anim_player.play("shoot")
|
||||
vibration()
|
||||
bullet_fire()
|
||||
spawn_casing()
|
||||
if chamber != null:
|
||||
revolver_chamber_rot_amt += 60
|
||||
if weapon_info.smoke_enabled:
|
||||
@@ -114,19 +120,21 @@ func spawn_mag():
|
||||
get_tree().get_root().add_child(instance_mag)
|
||||
|
||||
func spawn_casing():
|
||||
# Casing transform
|
||||
var instance_casing = weapon_info.casing.instantiate()
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
instance_casing.player_velocity = player.velocity * transform.basis
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
if weapon_info.casing != null:
|
||||
# Casing transform
|
||||
var instance_casing = weapon_info.casing.instantiate()
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
instance_casing.player_velocity = player.velocity * transform.basis
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
|
||||
|
||||
func spawn_revolver_casings():
|
||||
if casing_array.size() > 0:
|
||||
for i in casing_array:
|
||||
i.visible = false
|
||||
if weapon_info.casings_chamber_last > 0:
|
||||
var instance_casing = weapon_info.spawn_casing.instantiate()
|
||||
if casings_chamber_last > 0:
|
||||
var instance_casing = weapon_info.casing.instantiate()
|
||||
instance_casing.position = i.global_position
|
||||
instance_casing.random_rotation = false
|
||||
instance_casing.transform.basis = i.global_transform.basis
|
||||
@@ -134,7 +142,7 @@ func spawn_revolver_casings():
|
||||
instance_casing.rotation.x += deg_to_rad(90)
|
||||
instance_casing.linear_velocity.y = -(8 + rng.randf_range(0,3))
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
weapon_info.casings_chamber_last -= 1
|
||||
casings_chamber_last -= 1
|
||||
|
||||
func shotgun_pellet_spawn():
|
||||
|
||||
@@ -146,7 +154,7 @@ func shotgun_pellet_spawn():
|
||||
var lv_x = rng.randf_range(-weapon_info.shotgun_spread.x,weapon_info.shotgun_spread.x)
|
||||
var lv_y = rng.randf_range(-weapon_info.shotgun_spread.y,weapon_info.shotgun_spread.y)
|
||||
# instance bullet
|
||||
var instance_bullet = weapon_info.bullet.instantiate()
|
||||
var instance_bullet = weapon_info.bullet.asset.instantiate()
|
||||
instance_bullet.position = player.bullet_ray.global_position
|
||||
instance_bullet.transform.basis = player.bullet_ray.global_transform.basis
|
||||
instance_bullet.linear_velocity += instance_bullet.transform.basis * Vector3(lv_x, lv_y, -weapon_info.bullet_speed) + player.velocity
|
||||
@@ -155,9 +163,10 @@ func shotgun_pellet_spawn():
|
||||
pellets_remaining -= 1
|
||||
|
||||
vibration()
|
||||
fire_smoke.restart()
|
||||
fire_smoke.emitting = true
|
||||
smoke_timer.start()
|
||||
if fire_smoke != null:
|
||||
fire_smoke.restart()
|
||||
fire_smoke.emitting = true
|
||||
smoke_timer.start()
|
||||
player.recoil.add_recoil(Vector3(0,weapon_info.recoil_amount.y,weapon_info.recoil_amount.z),10,10)
|
||||
player.recoil.add_gun_recoil(weapon_info.recoil_amount.x)
|
||||
player.velocity += player.bullet_ray.global_basis * Vector3(0,0, weapon_info.kick_amount)
|
||||
|
||||
Reference in New Issue
Block a user