Adds lightning projectile
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.
This commit is contained in:
parent
ff62d67f54
commit
d0c2a7b3c8
12 changed files with 239 additions and 103 deletions
51
assets/projectiles/components/bolt.gd
Normal file
51
assets/projectiles/components/bolt.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
extends Node2D
|
||||
|
||||
var goal_point: Vector2 = Vector2(100, 100)
|
||||
var min_segment_size: float = 2
|
||||
var max_segment_size: float = 10
|
||||
var points: Array = []
|
||||
var emitting = true
|
||||
var final_goal: Vector2
|
||||
|
||||
@export var angle_var: float = 15
|
||||
|
||||
@onready var line: Line2D = $Line2D
|
||||
|
||||
func _ready():
|
||||
Log.pr("Bolt!")
|
||||
line.width = 2
|
||||
final_goal = goal_point - global_position
|
||||
$Timer.start(randf_range(0.1, 0.5))
|
||||
|
||||
func _on_timer_timeout():
|
||||
Log.pr("Timer timeout")
|
||||
if (points.size() > 0):
|
||||
points.pop_front()
|
||||
line.points = points
|
||||
|
||||
#Small variation for more organic look:
|
||||
$Timer.start(0.002 + randf_range(-0.001, 0.001))
|
||||
elif (emitting):
|
||||
update_points()
|
||||
line.points = points
|
||||
$Timer.start(0.1 + randf_range(-0.02, 0.1))
|
||||
|
||||
func update_points():
|
||||
final_goal = goal_point - global_position
|
||||
var curr_line_len = 0
|
||||
points = [Vector2()]
|
||||
var start_point = Vector2()
|
||||
min_segment_size = max(Vector2().distance_to(final_goal) / 40, 1)
|
||||
max_segment_size = min(Vector2().distance_to(final_goal) / 20, 10)
|
||||
while (curr_line_len < Vector2().distance_to(final_goal)):
|
||||
var move_vector = start_point.direction_to(final_goal) * randf_range(min_segment_size, max_segment_size)
|
||||
var new_point = start_point + move_vector
|
||||
var new_point_rotated = start_point + move_vector.rotated(deg_to_rad(randf_range(-angle_var, angle_var)))
|
||||
points.append(new_point_rotated)
|
||||
start_point = new_point
|
||||
curr_line_len = start_point.length()
|
||||
|
||||
points.append(final_goal)
|
||||
|
||||
func set_line_width(amount):
|
||||
line.width = amount
|
||||
1
assets/projectiles/components/bolt.gd.uid
Normal file
1
assets/projectiles/components/bolt.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bshl5y6qhgv2b
|
||||
22
assets/projectiles/components/bolt.tscn
Normal file
22
assets/projectiles/components/bolt.tscn
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cafaf3en63bp6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bshl5y6qhgv2b" path="res://assets/projectiles/components/bolt.gd" id="1_rrby1"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_sbfhf"]
|
||||
_data = [Vector2(0.0154639, 0.409091), 0.0, 0.0, 0, 0, Vector2(0.448454, 0.981818), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
point_count = 3
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_rrby1"]
|
||||
offsets = PackedFloat32Array(0.0264901, 0.0993377, 0.84106, 1)
|
||||
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0.865385, 1, 1, 1, 0)
|
||||
|
||||
[node name="Bolt" type="Node2D"]
|
||||
script = ExtResource("1_rrby1")
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="."]
|
||||
width_curve = SubResource("Curve_sbfhf")
|
||||
gradient = SubResource("Gradient_rrby1")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue