Implements a lightning projectile with visual effects. The lightning is created using a series of bolt components that dynamically adjust their shape. Also refactors the projectile system to use a base class. Removes unused modifiers from player script.
30 lines
950 B
GDScript
30 lines
950 B
GDScript
extends Resource
|
|
class_name PlayerCombat
|
|
|
|
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"):
|
|
player.weapon.fire(normalized_direction, mouse_position)
|
|
# Update animation
|
|
#update_animation()
|
|
|
|
func update_animation():
|
|
Log.pr(animated_sprite.animation)
|
|
if animated_sprite.animation != "throw":
|
|
Log.pr('Throwing animation!')
|
|
animated_sprite.play("throw")
|