bullet feels better, added spike traps

This commit is contained in:
derek
2024-11-05 16:09:13 -06:00
parent 3002c6e2db
commit 83e2365892
23 changed files with 626 additions and 93 deletions

View File

@@ -4,6 +4,7 @@ extends Node3D
@export_group("Gun Feel")
@export var gun_name : String
@export_enum("Auto", "Single", "Burst") var fire_mode: int
@export var hitscan_enabled : bool = false
@export var fov_zoom_amt = .98
@export var recoil_amount : Vector3 = Vector3(.2,.05,.05)
@export var max_ammo = 15
@@ -18,6 +19,7 @@ extends Node3D
@export_subgroup("Main Assets")
@export var flare_light : Node
@export var bullet : Resource
@export var bullet_fake : Resource
@export var bullethole : Resource
@export var casing : Resource
@export var mag : Resource
@@ -83,34 +85,15 @@ func shoot(delta):
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
if !anim_player.is_playing():
level_control.ammo_current[gun_index] -= 1
#RECOIL --- fix later to happen over a period of time
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
#audio and anims
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
audio_fire.play()
anim_player.play("shoot")
# 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
if player.gun_folded == false:
instance_bullet.transform.basis = player.bullet_ray.global_transform.basis
else:
instance_bullet.transform.basis = barrel_raycast.global_transform.basis
instance_bullet.bullet_speed = bullet_speed
instance_bullet.player_velocity = player.velocity
instance_bullet.bullet_drop = bullet_drop
instance_bullet.random_spread_amt = random_spread_amt
instance_bullet.bullet_damage = bullet_damage
instance_bullet.bullet_force_mod = bullet_force_mod
instance_bullet.instance_bullethole = bullethole.instantiate()
instance_bullet.player_position = player.global_position
get_tree().current_scene.add_child(instance_bullet)
# Casing transform
var instance_casing = casing.instantiate()
instance_casing.position = casing_ejector.global_position
instance_casing.transform.basis = casing_ejector.global_transform.basis
get_tree().get_root().add_child(instance_casing)
bullet_fire()
hitscan_fire()
spawn_casing()
player.recoil.add_recoil(recoil_amount,10,10)
if fire_mode != 0:
cycle_count -= 1
@@ -136,5 +119,42 @@ func spawn_mag():
instance_mag.transform.basis = mag_ejector.global_transform.basis
get_tree().get_root().add_child(instance_mag)
func spawn_casing():
# Casing transform
var instance_casing = casing.instantiate()
instance_casing.position = casing_ejector.global_position
instance_casing.transform.basis = casing_ejector.global_transform.basis
get_tree().get_root().add_child(instance_casing)
func bullet_fire():
var instance_bullet
if hitscan_enabled:
instance_bullet = bullet_fake.instantiate()
else:
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:
instance_bullet.transform.basis = player.bullet_ray.global_transform.basis
else:
instance_bullet.transform.basis = barrel_raycast.global_transform.basis
instance_bullet.bullet_speed = bullet_speed
instance_bullet.player_velocity = player.velocity * transform.basis
instance_bullet.bullet_drop = bullet_drop
instance_bullet.random_spread_amt = random_spread_amt
instance_bullet.bullet_damage = bullet_damage
instance_bullet.bullet_force_mod = bullet_force_mod
instance_bullet.instance_bullethole = bullethole.instantiate()
instance_bullet.player_position = player.global_position
get_tree().current_scene.add_child(instance_bullet)
func hitscan_fire():
if hitscan_enabled:
# Fire hitscan
if player.gun_folded == false:
player.bullet_ray.hitscan_fire(bullet_damage,bullet_force_mod,bullethole)
else:
barrel_raycast.hitscan_fire(bullet_damage,bullet_force_mod,bullethole)
func swapped_out():
queue_free()