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:
Dan Baker 2025-05-06 09:30:44 +01:00
parent d0c2a7b3c8
commit 1a959fbc0c
7 changed files with 232 additions and 41 deletions

View file

@ -5,20 +5,12 @@ var player: CharacterBody2D
var animated_sprite: AnimatedSprite2D
func process(_delta):
# Get mouse position in global coordinates
var mouse_position = player.get_global_mouse_position()
# Get player position (assuming this script is attached to the player)
var player_position = player.global_position
# Calculate direction vector from player to mouse
var direction = mouse_position - player_position
# You can normalize this vector if you want a unit vector (length of 1)
# This is useful if you only care about direction, not distance
var normalized_direction = direction.normalized()
if Input.is_action_pressed("fire"):
var mouse_position = player.get_global_mouse_position()
var player_position = player.global_position
var direction = mouse_position - player_position
var normalized_direction = direction.normalized()
player.weapon.fire(normalized_direction, mouse_position)
# Update animation
#update_animation()