Files
GrowlerFury/scripts/controllers/cpu_system/cpu_controller.gd
T

99 lines
2.9 KiB
GDScript
Raw Normal View History

class_name CPUController extends BaseController
func _process(_delta: float) -> void:
if not jets_collection: return
for jet: Jet in jets_collection.get_children():
if Globals.ControlMode.PLAYER_MODE == jet.controller.control_mode:
continue
process_jet_plan(jet)
func _controller_message(event: BaseEvent) -> void:
if event is InitSpawnsLoadedEvent:
handle_init_spawns_loaded_event()
func handle_init_spawns_loaded_event() -> void:
for jet: Jet in jets_collection.get_children():
create_jet_plan(jet)
func create_jet_plan(jet: Jet) -> void:
assign_jet_target(jet)
func assign_jet_target(jet: Jet) -> void:
for _jet: Jet in jets_collection.get_children():
if _jet.faction == jet.faction: continue
if _jet.targeted_by: continue
_jet.targeted_by = jet
jet.target = _jet
break
func process_jet_plan(jet: Jet) -> void:
if not is_instance_valid(jet.target): return
var target_local_position: Vector3 = jet.to_local(jet.target.global_position)
var target_direction: Vector3 = target_local_position.normalized()
jet.target_ray.target_position = target_direction * 8
if maxf(target_direction.z, 0.0) == 0.0:
get_node("../../base_ui/target_position_fb").text = "infront"
jet.controller.cpu.no_action()
if target_direction.x > 0.2:
jet.controller.cpu.yaw_right()
elif target_direction.x < -0.2:
jet.controller.cpu.yaw_left()
elif maxf(target_direction.y, 0.5) == 0.5:
jet.controller.cpu.no_action()
if target_direction.y > 0.2:
2026-11-01 17:33:28 -06:00
get_node("../../base_ui/target_position_ab").text = "above"
jet.controller.cpu.pitch_up()
elif target_direction.y < -0.2:
2026-11-01 17:33:28 -06:00
get_node("../../base_ui/target_position_ab").text = "below"
jet.controller.cpu.pitch_down()
elif maxf(target_direction.y, -0.5) == -0.5:
get_node("../../base_ui/target_position_ab").text = "below"
jet.controller.cpu.no_action()
if target_direction.y > 0.2:
jet.controller.cpu.yaw_right()
elif target_direction.y < -0.2:
jet.controller.cpu.yaw_left()
else:
get_node("../../base_ui/target_position_fb").text = "behind"
jet.controller.cpu.no_action()
if target_direction.x > 0.2:
jet.controller.cpu.yaw_right()
elif target_direction.x < -0.2:
jet.controller.cpu.yaw_left()
get_node("../../base_ui/target_z").text = str(target_direction.z)
get_node("../../base_ui/target_x").text = str(target_direction.x)
#var direction: Vector3 = (
#jet.target.global_position - jet.global_position
#).normalized()
# NOTE: (From GPT) Mostly works but with precession nor do I really understand it...
2026-11-01 17:33:28 -06:00
#var forward_dot: float = target_direction.dot(Vector3.UP)
#if forward_dot >= cos(deg_to_rad(37.5)):
#get_node("../../base_ui/target_position_fb").text = "infront"
#jet.controller.cpu.no_action()
#else:
#get_node("../../base_ui/target_position_fb").text = "behind"
#if target_direction.x >= 0.2:
#jet.controller.cpu.yaw_right()
#elif target_direction.x <= -0.2:
#jet.controller.cpu.yaw_left()