Files
SWGalaga/Scripts/turret_laser.gd

56 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

2024-06-05 06:59:39 -04:00
extends Area2D
@onready var turret_laser = $Sprite2D
2024-06-05 17:37:46 -04:00
2024-06-05 06:59:39 -04:00
var speed = 100
var target2 : Vector2
var new_rot
var direction
2024-06-05 06:59:39 -04:00
func initialize(firing_solution,target):
print('firing_solution='+str(firing_solution))
new_rot = firing_solution
#turret_laser.set_rotation(firing_solution)
2024-06-05 17:37:46 -04:00
#print(str(turret_laser))
#print(str(firing_solution))
2024-06-05 06:59:39 -04:00
target2 = target
#print(str(firing_solution))
func _ready():
2024-06-05 17:37:46 -04:00
set_rotation(new_rot)
direction = (target2 - global_position).normalized()
2024-06-05 17:37:46 -04:00
2024-06-05 06:59:39 -04:00
func _physics_process(delta):
#print(str(global_position.x - target.x))
#print(global_position)
#print(target2)
#print(typeof(global_position))
#print(typeof(target))
#var direction = (global_position - target2).normalized()
#print("target2 " + str(target2))
#print("direction normalized " + str(direction))
#print("target_far " + str(target_far))
#print("direction " + str(direction))
#print("target2 " + str(target2))
#global_position += (direction - global_position).normalized() * speed * delta
global_position += direction * speed * delta
if global_position.x >= 980:
#print("cleanup")
queue_free()
2024-06-05 17:37:46 -04:00
func _on_area_entered(area):
if area is player:
area.take_damage(1)
queue_free()
func _on_timer_timeout():
print("cleanup")
queue_free()