refactored bullet script, broke shotgun pellets which will need to be fixed

This commit is contained in:
derek
2025-03-25 16:55:22 -05:00
parent 3e3a0d2192
commit 8d0f925be6
24 changed files with 1283 additions and 122 deletions

View File

@@ -9,7 +9,6 @@ extends Projectile
var bounces = 0
var start_time
var end_time
var start_velocity
const EMISSION_MAX : float = 200
const EMISSION_LIFETIME : float = 1.75 #in seconds
@@ -17,39 +16,22 @@ const VELOCITY_REQUIRED_TO_HIT : float = 10
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
visible = false
start_time = Time.get_ticks_msec()
end_time = start_time + (EMISSION_LIFETIME * 1000)
start_velocity = linear_velocity.length()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var current_time = (Time.get_ticks_msec())/end_time
material.emission_energy_multiplier = clamp(lerp(EMISSION_MAX,0.0,current_time),0,EMISSION_MAX)
var distance_from_player = abs(self.global_position - player_position)
if distance_from_player.length() > 1.5:
visible = true
func _on_body_entered(body: Node) -> void:
bounces += 1
if bounces >= max_bounces:
despawn()
if body != null and !body.is_in_group("player") and linear_velocity.length() >= VELOCITY_REQUIRED_TO_HIT:
if body.is_in_group("switch"):
body.hit(bullet_damage)
if body.has_method("hit") and !body.is_in_group("player"):
body.hit(1)
if body.is_in_group("breakable"):
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
body.breaking(current_velocity)
if linear_velocity.length() >= VELOCITY_REQUIRED_TO_HIT:
damage(body)
func despawn():
collision_shape.disabled = true