extends Area2D #preload muzzle positions @onready var muzzle = $Muzzle1 @onready var mainray = $RayCast2D @onready var turret_center = $Turret/turret_Center @onready var turret_muzzle = $Turret/turret_muzzle @onready var target_ray = $Turret/target_confirm @onready var turret = $Turret @onready var mainCannonFire = $refire_timer1 @onready var turret_timer = $refire_timer2 #signal dont expect it to work signal enemy_died() signal missile_spawn() #set speed to an int var speed : int = 20 #set health var health : int = 3 #can the main gun fire? (rate of fire control) var main_cannon = true #can turret fire? (rate of fire control) var turret_cannon = true var firing_solution = null var target_area = null #reset raycast, setup settings func _ready(): target_ray.exclude_parent = true target_ray.collide_with_areas = true mainray.exclude_parent = true mainray.collide_with_areas = true #main loop func _physics_process(delta): #movement global_position.y += speed * delta #main cannon firing if mainray.is_colliding and mainray.get_collider is player: if main_cannon == true: fire_main_cannon() main_cannon = false mainCannonFire.start() aim_turret(delta) if target_ray.is_colliding and target_ray.get_collider() is player: if turret_cannon == true: fire_turret(turret_muzzle,firing_solution,target_area) turret_timer.start() turret_cannon = false #func aim_turret(delta): #var target : Vector2 = player.global_position #var turret_pos = turret.global_position #var target_rot = atan2(target.x - turret_pos.x, target.y - turret_pos.y) #var current_rotation = turret.rotation #current_rotation += current_rotation * 0.90 + target_rot * 0.10 * 5 * (3.149 / 180) #turret.rotate(current_rotation) #turret.rotation(atan2(target.x - turret_pos.x,target.y - turret_pos.y)) #figured out with loki, holy shit this was annoying func aim_turret(delta): var target : Vector2 = get_tree().current_scene.player.global_position var turret_pos = turret.global_position var target_rot = atan2(target.x - turret_pos.x, target.y - turret_pos.y) var target_pos = get_tree().current_scene.player.global_position var current_rotation = turret.rotation var speed = 5 #in degrees, can adjust var direction = 1 if target_rot < current_rotation: #may need to be "<" direction = -1 #current_rotation += direction * speed * (PI/180) * delta #turret.look_at(target_pos) #turret.rotation(current_rotation) #turret.rotation = current_rotation #current_rotation += current_rotation * 0.90 + target_rot * 0.10 #turret.set_rotation(atan2(target.x - turret_pos.x,target.y - turret_pos.y)) #turret.set_rotation(atan2(turret_pos.x - target.x, turret_pos.y - target_pos.y)) turret.set_rotation(atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180)) firing_solution = atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180) target_area = target_pos func fire_turret(location,rotation,target_area): get_tree().current_scene.firey_wingturret(location,rotation,target_area) func take_damage(damage): health -= damage if health <= 0: $death_timer.start() get_tree().current_scene.scored() power_up_check() #firing the lazors! func fire_main_cannon(): get_tree().current_scene.fire_y_wing_main(muzzle.global_position) func power_up_check(): var index = randi() % 51 if index <= 39: pass elif index >= 40 and index <= 48: get_tree().current_scene.missile_spawn(muzzle.global_position) func _on_refire_timer_1_timeout(): main_cannon = true func _on_death_timer_timeout(): emit_signal("enemy_died") queue_free() func _on_area_entered(area): if area is player: area.take_damage(1) func _on_refire_timer_2_timeout(): turret_cannon = true