Improves lightning projectile behavior
Refactors the lightning projectile to handle collisions more effectively. It now stops upon hitting an enemy or object, triggers an explosion, and spawns child projectiles from the collision point. The lightning bolt's collision shape is dynamically updated to match the remaining distance to the target or the collision point. Also adds more test enemies to the map for testing purposes.
This commit is contained in:
parent
d0c2a7b3c8
commit
1a959fbc0c
7 changed files with 232 additions and 41 deletions
|
|
@ -15,7 +15,7 @@ signal on_destroyed(projectile)
|
|||
# Modifier-related properties
|
||||
var pierce_count: int = 0
|
||||
var has_explosive_impact: bool = true
|
||||
var explosion_projectile_count: int = 2
|
||||
var explosion_projectile_count: int = 3
|
||||
var explosion_projectile_damage_mult: float = 0.5
|
||||
var explosion_projectile_speed: float = 300.0
|
||||
var explosion_spread_angle: float = 360.0 # Full circle by default
|
||||
|
|
@ -24,13 +24,13 @@ var explosion_spread_angle: float = 360.0 # Full circle by default
|
|||
var source_weapon: RangedWeapon # Reference to the weapon that fired this
|
||||
var lifetime_timer: Timer
|
||||
# Add a variable to track the entity that triggered the explosion
|
||||
var ignore_target = null
|
||||
var ignore_target = []
|
||||
|
||||
func _on_body_entered(body):
|
||||
# Check if this is a body we should ignore
|
||||
if body == ignore_target:
|
||||
if ignore_target.has(body):
|
||||
Log.pr("Ignoring body: ", body.name)
|
||||
return
|
||||
|
||||
|
||||
if body.is_in_group("enemies") and is_friendly:
|
||||
Log.pr("Hit enemy: ", body.name)
|
||||
# Deal damage to enemy
|
||||
|
|
@ -47,7 +47,7 @@ func _on_body_entered(body):
|
|||
# Handle explosive impact
|
||||
if has_explosive_impact:
|
||||
# Store the target that triggered the explosion
|
||||
ignore_target = body
|
||||
ignore_target.append(body)
|
||||
_trigger_explosion()
|
||||
|
||||
# Destroy the projectile
|
||||
|
|
@ -65,7 +65,9 @@ func _trigger_explosion():
|
|||
func _spawn_explosion_projectiles():
|
||||
for i in range(explosion_projectile_count):
|
||||
# Create a new projectile
|
||||
Log.pr("Spawning explosion projectile")
|
||||
var new_proj = duplicate()
|
||||
Log.pr("New projectile: ", new_proj)
|
||||
new_proj.global_position = global_position
|
||||
|
||||
# Calculate new direction based on spread
|
||||
|
|
@ -87,6 +89,10 @@ func _spawn_explosion_projectiles():
|
|||
# Add to scene tree
|
||||
get_tree().root.call_deferred("add_child", new_proj)
|
||||
|
||||
func set_projectile_scale(new_scale: Vector2):
|
||||
# Set the scale of the projectile
|
||||
self.scale = new_scale
|
||||
|
||||
func destroy():
|
||||
emit_signal("on_destroyed", self)
|
||||
queue_free()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue