Moved to pith verbage; CPUController WIP testing
This commit is contained in:
@@ -8,7 +8,7 @@ func _process(_delta: float) -> void:
|
||||
if Globals.ControlMode.PLAYER_MODE == jet.controller.control_mode:
|
||||
continue
|
||||
|
||||
process_jet_plan(jet.controller.cpu)
|
||||
process_jet_plan(jet)
|
||||
|
||||
func _controller_message(event: BaseEvent) -> void:
|
||||
if event is InitSpawnsLoadedEvent:
|
||||
@@ -22,7 +22,71 @@ func handle_init_spawns_loaded_event() -> void:
|
||||
create_jet_plan(jet)
|
||||
|
||||
func create_jet_plan(jet: Jet) -> void:
|
||||
print(jet)
|
||||
assign_jet_target(jet)
|
||||
|
||||
func process_jet_plan(jet: CPU) -> void:
|
||||
jet.yaw_left()
|
||||
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 direction: Vector3 = (
|
||||
jet.target.global_position - jet.global_position
|
||||
).normalized()
|
||||
|
||||
var target_basis = Basis.looking_at(direction, Vector3.UP)
|
||||
var target_rotation = target_basis.get_euler()
|
||||
var current_rotation = jet.global_rotation
|
||||
|
||||
var yaw_error = wrapf(
|
||||
target_rotation.y - current_rotation.y,
|
||||
-PI,
|
||||
PI
|
||||
)
|
||||
|
||||
var pitch_error = wrapf(
|
||||
target_rotation.x - current_rotation.x,
|
||||
-PI,
|
||||
PI
|
||||
)
|
||||
|
||||
var deadzone = deg_to_rad(2.0)
|
||||
|
||||
if yaw_error > deadzone:
|
||||
jet.controller.cpu.yaw_right()
|
||||
elif yaw_error < -deadzone:
|
||||
jet.controller.cpu.yaw_left()
|
||||
else:
|
||||
jet.controller.cpu.no_action()
|
||||
|
||||
if pitch_error > deadzone:
|
||||
jet.controller.cpu.pitch_down()
|
||||
elif pitch_error < -deadzone:
|
||||
jet.controller.cpu.pitch_up()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#func process_jet_plan(jet: Jet) -> void:
|
||||
#var direction = (jet.target.global_position - jet.global_position).normalized()
|
||||
#var target_basis = jet.looking_at(direction, Vector3.UP)
|
||||
#var target_rotation = target_basis.get_euler()
|
||||
|
||||
|
||||
#var direction = jet.target.global_position - jet.global_position
|
||||
#var desired_rotation = jet.look_rotation(direction)
|
||||
|
||||
#var rotation_error = desired_rotation - jet.rotation
|
||||
|
||||
#jet.pitch_input = calculate_pitch(rotation_error)
|
||||
#jet.yaw_input = calculate_yaw(rotation_error)
|
||||
#jet.roll_input = calculate_roll(rotation_error)
|
||||
#jet.throttle = calculate_throttle(distance)
|
||||
|
||||
Reference in New Issue
Block a user