the-crypt/magic/Beams/Beam.gd

28 lines
550 B
GDScript3
Raw Normal View History

2020-07-21 00:13:31 -05:00
extends Node2D
class_name Beam
var damage = 1
var energy_cost = 1
2020-07-21 00:13:31 -05:00
var max_cast = Vector2(400, 0)
func get_collider():
2020-07-21 18:08:31 -05:00
$FireSound.play(0.0)
return $RayCast2D.get_collider()
func activate():
$Beam.visible = true
$RayCast2D.enabled = true
func deactivate():
$Beam.visible = false
$RayCast2D.enabled = false
2020-07-21 00:13:31 -05:00
func _physics_process(delta):
$RayCast2D.cast_to = max_cast
if $RayCast2D.is_colliding():
$End.global_position = $RayCast2D.get_collision_point()
2020-07-21 00:13:31 -05:00
else:
$End.position = max_cast
$Beam.region_rect.end.x = $End.position.length()