2026-10-25 16:22:34 -05:00
|
|
|
class_name CPUController extends BaseController
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
|
if not jets_collection: return
|
|
|
|
|
|
|
|
|
|
for jet: Jet in jets_collection.get_children():
|
2026-10-25 19:45:31 -05:00
|
|
|
if Globals.ControlMode.PLAYER_MODE == jet.controller.control_mode:
|
|
|
|
|
continue
|
|
|
|
|
|
2026-10-25 23:12:51 -05:00
|
|
|
process_jet_plan(jet)
|
2026-10-25 19:45:31 -05:00
|
|
|
|
|
|
|
|
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:
|
2026-10-25 23:12:51 -05:00
|
|
|
assign_jet_target(jet)
|
2026-10-25 16:22:34 -05:00
|
|
|
|
2026-10-25 23:12:51 -05:00
|
|
|
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
|
|
|
|
|
|
2026-10-30 23:08:47 -05:00
|
|
|
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
|
2026-10-25 23:12:51 -05:00
|
|
|
|
2026-11-05 20:47:05 -06:00
|
|
|
#NOTE: When using unit (normalized) vectors, the result will always be
|
|
|
|
|
# between -1.0 (180 degree angle) when the vectors are facing opposite
|
|
|
|
|
# directions, and 1.0 (0 degree angle) when the vectors are aligned.
|
|
|
|
|
|
|
|
|
|
var forward_dot: float = target_direction.dot(Vector3.UP)
|
|
|
|
|
var lr_dot: float = target_direction.dot(Vector3.RIGHT)
|
|
|
|
|
print(rad_to_deg(cosh(forward_dot)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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)
|
2026-10-31 01:39:21 -05:00
|
|
|
|
2026-10-25 23:12:51 -05:00
|
|
|
|
2026-10-30 23:08:47 -05:00
|
|
|
#var direction: Vector3 = (
|
|
|
|
|
#jet.target.global_position - jet.global_position
|
|
|
|
|
#).normalized()
|
2026-10-31 01:39:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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)
|
2026-10-31 01:39:21 -05:00
|
|
|
#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()
|