Cleaned up notes; restructured test scene plus cpu controller script; added WIP action stack logic
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class_name ActionBase extends Node
|
||||
|
||||
|
||||
func do(_jet: Jet) -> void:
|
||||
assert(false, "Must override 'do' method from child")
|
||||
func process(_jet: Jet) -> void:
|
||||
assert(false, "Must override 'process' method from child")
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
class_name MoveTowards extends ActionBase
|
||||
|
||||
|
||||
func do(jet: Jet) -> void:
|
||||
func process(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
|
||||
jet.target_direction = target_direction
|
||||
|
||||
#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.
|
||||
# Note also that, probably want to align order around node 'rotation_order' which is YXZ
|
||||
var forward_dot: float = target_direction.dot(Vector3.UP)
|
||||
var ud_dot: float = target_direction.dot(Vector3.FORWARD)
|
||||
var lr_dot: float = target_direction.dot(Vector3.RIGHT)
|
||||
var ud_dot: float = target_direction.dot(Vector3.FORWARD)
|
||||
|
||||
|
||||
jet.controller.cpu.yaw_left()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class_name RollLeft extends ActionBase
|
||||
|
||||
|
||||
func process(jet: Jet) -> void:
|
||||
if not is_instance_valid(jet): return
|
||||
|
||||
jet.controller.cpu.roll_left()
|
||||
@@ -0,0 +1 @@
|
||||
uid://daep5cdrl6pwv
|
||||
@@ -0,0 +1,12 @@
|
||||
class_name RollLeftSideUp extends ActionBase
|
||||
|
||||
|
||||
func process(jet: Jet) -> void:
|
||||
if not is_instance_valid(jet): return
|
||||
check_orientation(jet)
|
||||
jet.controller.cpu.roll_left()
|
||||
|
||||
|
||||
func check_orientation(jet: Jet) -> void:
|
||||
#var rotation_dot = clampf(jet.rotation_degrees.z / 360.0, -1, 1)
|
||||
var rotation_norm = jet.rotation_degrees.normalized()
|
||||
@@ -0,0 +1 @@
|
||||
uid://tqa0386hofab
|
||||
@@ -0,0 +1,7 @@
|
||||
class_name RollRight extends ActionBase
|
||||
|
||||
|
||||
func process(jet: Jet) -> void:
|
||||
if not is_instance_valid(jet): return
|
||||
|
||||
jet.controller.cpu.roll_right()
|
||||
@@ -0,0 +1 @@
|
||||
uid://jgirej8jaxa3
|
||||
@@ -0,0 +1,12 @@
|
||||
class_name RollRightSideUp extends ActionBase
|
||||
|
||||
|
||||
func process(jet: Jet) -> void:
|
||||
if not is_instance_valid(jet): return
|
||||
check_orientation(jet)
|
||||
jet.controller.cpu.roll_right()
|
||||
|
||||
|
||||
func check_orientation(jet: Jet) -> void:
|
||||
#var rotation_dot = clampf(jet.rotation_degrees.z / 360.0, -1, 1)
|
||||
var rotation_norm = jet.rotation_degrees.normalized()
|
||||
@@ -0,0 +1 @@
|
||||
uid://gp6yl6ti2xvu
|
||||
@@ -34,67 +34,77 @@ func assign_jet_target(jet: Jet) -> void:
|
||||
|
||||
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:
|
||||
jet.strategy_stack.process_action(jet)
|
||||
|
||||
|
||||
|
||||
#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)
|
||||
#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 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()
|
||||
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()
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
class_name StrategyStack extends Node
|
||||
|
||||
|
||||
|
||||
var active_action: ActionBase
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
tree_entered.connect(add_action)
|
||||
tree_exited.connect(remove_action)
|
||||
child_entered_tree.connect( add_action.bind() )
|
||||
child_exiting_tree.connect( remove_action.bind() )
|
||||
|
||||
|
||||
func add_action() -> void:
|
||||
pass
|
||||
func add_action(action: ActionBase) -> void:
|
||||
if active_action: return
|
||||
active_action = action
|
||||
|
||||
func remove_action() -> void:
|
||||
pass
|
||||
func remove_action(action: ActionBase) -> void:
|
||||
if not active_action == action: return
|
||||
# NOTE: 1st node hasn't actually been removed yet
|
||||
active_action = null if not get_child_count() > 1 else get_child(1)
|
||||
|
||||
func process_action(jet: Jet) -> void:
|
||||
var action = get_child(0)
|
||||
if not action: return
|
||||
action.do(jet)
|
||||
if not active_action: return
|
||||
active_action.process(jet)
|
||||
|
||||
@@ -5,8 +5,6 @@ var commands: Globals.CompoundCommand = Globals.CompoundCommand.new()
|
||||
|
||||
|
||||
func process(_delta: float) -> Globals.CompoundCommand:
|
||||
no_action()
|
||||
|
||||
if Input.is_action_pressed("pitch_up"):
|
||||
commands.PITCH = Globals.ControllerCommand.PITCH_UP
|
||||
elif Input.is_action_pressed("pitch_down"):
|
||||
|
||||
Reference in New Issue
Block a user