Improves projectile handling and modifiers
Refactors projectile spawning to allow for customized spawn locations and stat assignment. Applies modifiers to projectiles at the time of spawning, enabling dynamic adjustments to projectile behavior.
This commit is contained in:
parent
70839387ca
commit
fac3327c22
6 changed files with 74 additions and 11 deletions
|
|
@ -7,13 +7,16 @@ extends ProjectileBase
|
|||
# Add variables to track collision state
|
||||
var has_collided: bool = false
|
||||
var collision_point: Vector2 = Vector2.ZERO
|
||||
var existing_shape: CollisionShape2D = null
|
||||
|
||||
func _init() -> void:
|
||||
#super._init()
|
||||
super._init()
|
||||
Log.pr("ProjectileLightning _init")
|
||||
|
||||
func _ready():
|
||||
super._ready()
|
||||
Log.pr(ignore_target)
|
||||
Log.pr('Source Weapon: ', source_weapon)
|
||||
|
||||
lifetime_timer = Timer.new()
|
||||
add_child(lifetime_timer)
|
||||
|
|
@ -36,7 +39,7 @@ func _ready():
|
|||
func ensure_collision_shape():
|
||||
# Check if we already have a collision shape
|
||||
var has_collision_shape = false
|
||||
var existing_shape = null
|
||||
existing_shape = null
|
||||
|
||||
for child in get_children():
|
||||
if child is CollisionShape2D:
|
||||
|
|
@ -75,6 +78,9 @@ func update_collision_shape(collision_shape = null):
|
|||
if collision_shape:
|
||||
var capsule = collision_shape.shape as CapsuleShape2D
|
||||
if capsule:
|
||||
#collision_shape.global_position = source_weapon.global_position
|
||||
global_position = source_weapon.global_position
|
||||
|
||||
var target = collision_point if has_collided else target_position
|
||||
var distance = global_position.distance_to(target)
|
||||
var dir = (target - global_position).normalized()
|
||||
|
|
@ -87,12 +93,13 @@ func update_collision_shape(collision_shape = null):
|
|||
|
||||
# Fix position: Move the shape so it starts at origin
|
||||
collision_shape.position = dir * (distance / 2)
|
||||
|
||||
|
||||
|
||||
func _process(delta):
|
||||
# Update target positions for lightning bolts
|
||||
for child in lightning:
|
||||
if child is LightningBolt:
|
||||
child.global_position = source_weapon.global_position
|
||||
child.goal_point = collision_point if has_collided else target_position
|
||||
|
||||
# Update collision shape if it exists
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue