the-crypt/magic/Beams/PhantomBeam.gd

33 lines
730 B
GDScript3
Raw Normal View History

2020-07-21 17:49:04 -05:00
extends Beam
func _ready():
energy_cost = 3
damage = 1
func activate():
$Beam.visible = true
$RayCast2D.enabled = true
$Area2D.monitoring = true
2020-07-21 18:08:31 -05:00
func deactivate():
$Beam.visible = false
$RayCast2D.enabled = false
$Area2D.monitoring = false
2020-07-21 17:49:04 -05:00
func get_collider():
2020-07-21 18:08:31 -05:00
$FireSound.play(0.0)
2020-07-21 17:49:04 -05:00
var r = []
for b in $Area2D.get_overlapping_bodies():
r.append(b)
return r
func _physics_process(delta):
$RayCast2D.cast_to = max_cast
if $RayCast2D.is_colliding():
$End.global_position = $RayCast2D.get_collision_point()
else:
$End.position = max_cast
$Beam.region_rect.end.x = $End.position.length()
$Area2D/CollisionShape2D.shape.extents.x = $End.position.length() / 2
$Area2D.position.x = $End.position.length() / 2