bullet visible by distance

This commit is contained in:
derek
2024-07-17 12:46:02 -05:00
parent a917dd2c88
commit c959835b40
4 changed files with 9 additions and 3 deletions

View File

@@ -396,7 +396,7 @@ script = ExtResource("2_6i1l4")
gun_name = "Mac 10" gun_name = "Mac 10"
recoil_amount = 1.0 recoil_amount = 1.0
max_ammo = 30 max_ammo = 30
bullet_drop = 0.1 bullet_drop = 0.07
random_spread_amt = 0.5 random_spread_amt = 0.5
fire_pitch_scale_amt = 0.1 fire_pitch_scale_amt = 0.1
flare_light = NodePath("mac10/SpotLight3D") flare_light = NodePath("mac10/SpotLight3D")

View File

@@ -6,6 +6,8 @@ var random_spread_amt
var bullet_damage var bullet_damage
var instance_bullethole var instance_bullethole
var bullet_force_mod = 1.0 var bullet_force_mod = 1.0
var distance_from_player
var player
@onready var mesh = $gunbullet1 @onready var mesh = $gunbullet1
@onready var ray = $RayCast3D @onready var ray = $RayCast3D
@@ -39,8 +41,10 @@ func _process(delta):
position += transform.basis * Vector3(0, 0, -bullet_speed) * delta position += transform.basis * Vector3(0, 0, -bullet_speed) * delta
rotation.x = clamp(rotation.x - delta * bullet_drop,deg_to_rad(-90),deg_to_rad(90)) rotation.x = clamp(rotation.x - delta * bullet_drop,deg_to_rad(-90),deg_to_rad(90))
await get_tree().create_timer(.02 * Engine.time_scale * (150/bullet_speed)).timeout distance_from_player = abs(self.global_position - player.global_position)
visible = true
if distance_from_player.x > 2 or distance_from_player.y > 2 or distance_from_player.z > 2:
visible = true
if ray.is_colliding() and !ray.get_collider().is_in_group("player"): if ray.is_colliding() and !ray.get_collider().is_in_group("player"):

View File

@@ -105,6 +105,7 @@ func shoot(player,delta):
instance_bullet.bullet_damage = bullet_damage instance_bullet.bullet_damage = bullet_damage
instance_bullet.bullet_force_mod = bullet_force_mod instance_bullet.bullet_force_mod = bullet_force_mod
instance_bullet.instance_bullethole = bullethole.instantiate() instance_bullet.instance_bullethole = bullethole.instantiate()
instance_bullet.player = player
get_tree().get_root().add_child(instance_bullet) get_tree().get_root().add_child(instance_bullet)
# Casing transform # Casing transform

View File

@@ -152,6 +152,7 @@ func fire(delta):
instance_bullet.bullet_damage = bullet_damage instance_bullet.bullet_damage = bullet_damage
instance_bullet.random_spread_amt = random_spread_amt instance_bullet.random_spread_amt = random_spread_amt
instance_bullet.bullet_force_mod = bullet_force_mod instance_bullet.bullet_force_mod = bullet_force_mod
instance_bullet.player = player
instance_bullet.instance_bullethole = bullethole.instantiate() instance_bullet.instance_bullethole = bullethole.instantiate()
get_tree().get_root().add_child(instance_bullet) get_tree().get_root().add_child(instance_bullet)
player.weapon_recoil() player.weapon_recoil()