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) assign_jet_action(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 assign_jet_action(jet: Jet) -> void: jet.strategy_stack.add_child( MoveTowards.new() ) jet.strategy_stack.add_child( RollLeftSideUp.new() ) func process_jet_plan(jet: Jet) -> void: #process_jet_plan_old(jet) #process_jet_plan_gpt(jet) #jet.strategy_stack.process_action(jet) var target_local_position: Vector3 = jet.to_local(jet.target.global_position) var target_direction: Vector3 = target_local_position.normalized() jet.target_direction = target_direction func process_jet_plan_old(jet: Jet) -> void: #var direction: Vector3 = ( #jet.target.global_position - jet.global_position #).normalized() 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 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: get_node("../../base_ui/target_position_ab").text = "above" jet.controller.cpu.pitch_up() elif target_direction.y < -0.2: 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) func process_jet_plan_gpt(jet: Jet) -> void: # NOTE: (From GPT) Mostly works but with precession nor do I really understand it... var target_direction: Vector3 = jet.to_local(jet.target.global_position) 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()