adde compound command calling for multi input control; added notes on dot product; testing stuff in skunk works folder
This commit is contained in:
@@ -38,46 +38,60 @@ func process_jet_plan(jet: Jet) -> void:
|
||||
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()
|
||||
#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.
|
||||
|
||||
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()
|
||||
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)))
|
||||
|
||||
|
||||
get_node("../../base_ui/target_z").text = str(target_direction.z)
|
||||
get_node("../../base_ui/target_x").text = str(target_direction.x)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
|
||||
#var direction: Vector3 = (
|
||||
|
||||
@@ -10,27 +10,27 @@ class_name JetController extends Node
|
||||
@onready var player: Player = $player
|
||||
|
||||
|
||||
func process(delta: float) -> Globals.ControllerCommand:
|
||||
func process(delta: float) -> Globals.CompoundCommand:
|
||||
match control_mode:
|
||||
Globals.ControlMode.CPU_MODE:
|
||||
return cpu.process(delta)
|
||||
Globals.ControlMode.PLAYER_MODE:
|
||||
return player.process(delta)
|
||||
_:
|
||||
return Globals.ControllerCommand.NONE
|
||||
return Globals.CompoundCommand.new()
|
||||
|
||||
func physics_process(delta: float) -> Globals.ControllerCommand:
|
||||
func physics_process(delta: float) -> Globals.CompoundCommand:
|
||||
if Globals.ControlMode.CPU_MODE == control_mode:
|
||||
return cpu.physics_process(delta)
|
||||
elif Globals.ControlMode.PLAYER_MODE == control_mode:
|
||||
return player.physics_process(delta)
|
||||
|
||||
return Globals.ControllerCommand.NONE
|
||||
return Globals.CompoundCommand.new()
|
||||
|
||||
func unhandled_input(event: InputEvent) -> Globals.ControllerCommand:
|
||||
func unhandled_input(event: InputEvent) -> Globals.CompoundCommand:
|
||||
if Globals.ControlMode.CPU_MODE == control_mode:
|
||||
return cpu.unhandled_input(event)
|
||||
elif Globals.ControlMode.PLAYER_MODE == control_mode:
|
||||
return player.unhandled_input(event)
|
||||
|
||||
return Globals.ControllerCommand.NONE
|
||||
return Globals.CompoundCommand.new()
|
||||
|
||||
+20
-18
@@ -1,46 +1,48 @@
|
||||
class_name CPU extends Node
|
||||
|
||||
|
||||
var command: Globals.ControllerCommand = Globals.ControllerCommand.NONE
|
||||
var throttle: Globals.ControllerCommand = Globals.ControllerCommand.NONE
|
||||
var commands: Globals.CompoundCommand = Globals.CompoundCommand.new()
|
||||
|
||||
|
||||
func process(_delta: float) -> Globals.ControllerCommand:
|
||||
return command
|
||||
func process(_delta: float) -> Globals.CompoundCommand:
|
||||
return commands
|
||||
|
||||
func physics_process(_delta: float) -> Globals.ControllerCommand:
|
||||
return command
|
||||
func physics_process(_delta: float) -> Globals.CompoundCommand:
|
||||
return commands
|
||||
|
||||
func unhandled_input(_event: InputEvent) -> Globals.ControllerCommand:
|
||||
return command
|
||||
func unhandled_input(_event: InputEvent) -> Globals.CompoundCommand:
|
||||
return commands
|
||||
|
||||
|
||||
func pitch_up() -> void:
|
||||
command = Globals.ControllerCommand.PITCH_UP
|
||||
commands.PITCH = Globals.ControllerCommand.PITCH_UP
|
||||
|
||||
func pitch_down() -> void:
|
||||
command = Globals.ControllerCommand.PITCH_DOWN
|
||||
commands.PITCH = Globals.ControllerCommand.PITCH_DOWN
|
||||
|
||||
func yaw_left() -> void:
|
||||
command = Globals.ControllerCommand.YAW_LEFT
|
||||
commands.YAW = Globals.ControllerCommand.YAW_LEFT
|
||||
|
||||
func yaw_right() -> void:
|
||||
command = Globals.ControllerCommand.YAW_RIGHT
|
||||
commands.YAW = Globals.ControllerCommand.YAW_RIGHT
|
||||
|
||||
func roll_left() -> void:
|
||||
command = Globals.ControllerCommand.ROLL_LEFT
|
||||
commands.ROLL = Globals.ControllerCommand.ROLL_LEFT
|
||||
|
||||
func roll_right() -> void:
|
||||
command = Globals.ControllerCommand.ROLL_RIGHT
|
||||
commands.ROLL = Globals.ControllerCommand.ROLL_RIGHT
|
||||
|
||||
func throttle_up() -> void:
|
||||
throttle = Globals.ControllerCommand.THROTTLE_UP
|
||||
commands.THROTTLE = Globals.ControllerCommand.THROTTLE_UP
|
||||
|
||||
func throttle_down() -> void:
|
||||
throttle = Globals.ControllerCommand.THROTTLE_DOWN
|
||||
commands.THROTTLE = Globals.ControllerCommand.THROTTLE_DOWN
|
||||
|
||||
func throttle_neutral() -> void:
|
||||
throttle = Globals.ControllerCommand.NONE
|
||||
commands.THROTTLE = Globals.ControllerCommand.NONE
|
||||
|
||||
func no_action() -> void:
|
||||
command = Globals.ControllerCommand.NONE
|
||||
commands.PITCH = Globals.ControllerCommand.NONE
|
||||
commands.YAW = Globals.ControllerCommand.NONE
|
||||
commands.ROLL = Globals.ControllerCommand.NONE
|
||||
commands.THROTTLE = Globals.ControllerCommand.NONE
|
||||
|
||||
@@ -1,28 +1,42 @@
|
||||
class_name Player extends Node
|
||||
|
||||
|
||||
func process(_delta: float) -> Globals.ControllerCommand:
|
||||
var commands: Globals.CompoundCommand = Globals.CompoundCommand.new()
|
||||
|
||||
|
||||
func process(_delta: float) -> Globals.CompoundCommand:
|
||||
no_action()
|
||||
|
||||
if Input.is_action_pressed("pitch_up"):
|
||||
return Globals.ControllerCommand.PITCH_UP
|
||||
if Input.is_action_pressed("pitch_down"):
|
||||
return Globals.ControllerCommand.PITCH_DOWN
|
||||
commands.PITCH = Globals.ControllerCommand.PITCH_UP
|
||||
elif Input.is_action_pressed("pitch_down"):
|
||||
commands.PITCH = Globals.ControllerCommand.PITCH_DOWN
|
||||
|
||||
if Input.is_action_pressed("yaw_left"):
|
||||
return Globals.ControllerCommand.YAW_LEFT
|
||||
if Input.is_action_pressed("yaw_right"):
|
||||
return Globals.ControllerCommand.YAW_RIGHT
|
||||
commands.YAW = Globals.ControllerCommand.YAW_LEFT
|
||||
elif Input.is_action_pressed("yaw_right"):
|
||||
commands.YAW = Globals.ControllerCommand.YAW_RIGHT
|
||||
|
||||
if Input.is_action_pressed("roll_left"):
|
||||
return Globals.ControllerCommand.ROLL_LEFT
|
||||
if Input.is_action_pressed("roll_right"):
|
||||
return Globals.ControllerCommand.ROLL_RIGHT
|
||||
commands.ROLL = Globals.ControllerCommand.ROLL_LEFT
|
||||
elif Input.is_action_pressed("roll_right"):
|
||||
commands.ROLL = Globals.ControllerCommand.ROLL_RIGHT
|
||||
|
||||
if Input.is_action_pressed("throttle_up"):
|
||||
return Globals.ControllerCommand.THROTTLE_UP
|
||||
if Input.is_action_pressed("throttle_down"):
|
||||
return Globals.ControllerCommand.THROTTLE_DOWN
|
||||
commands.THROTTLE = Globals.ControllerCommand.THROTTLE_UP
|
||||
elif Input.is_action_pressed("throttle_down"):
|
||||
commands.THROTTLE = Globals.ControllerCommand.THROTTLE_DOWN
|
||||
|
||||
return Globals.ControllerCommand.NONE
|
||||
return commands
|
||||
|
||||
func physics_process(_delta: float) -> Globals.ControllerCommand:
|
||||
return Globals.ControllerCommand.NONE
|
||||
func physics_process(_delta: float) -> Globals.CompoundCommand:
|
||||
return Globals.CompoundCommand.new()
|
||||
|
||||
func unhandled_input(_event: InputEvent) -> Globals.ControllerCommand:
|
||||
return Globals.ControllerCommand.NONE
|
||||
func unhandled_input(_event: InputEvent) -> Globals.CompoundCommand:
|
||||
return Globals.CompoundCommand.new()
|
||||
|
||||
func no_action() -> void:
|
||||
commands.PITCH = Globals.ControllerCommand.NONE
|
||||
commands.YAW = Globals.ControllerCommand.NONE
|
||||
commands.ROLL = Globals.ControllerCommand.NONE
|
||||
commands.THROTTLE = Globals.ControllerCommand.NONE
|
||||
|
||||
@@ -14,25 +14,38 @@ var speed: float = float(MIN_SPEED)
|
||||
|
||||
|
||||
func do_action(
|
||||
action: Globals.ControllerCommand,
|
||||
action: Globals.CompoundCommand,
|
||||
delta: float,
|
||||
jet: Jet
|
||||
) -> void:
|
||||
var change_rate: float = deg_to_rad(1) * delta
|
||||
|
||||
match action:
|
||||
match action.PITCH:
|
||||
Globals.ControllerCommand.PITCH_UP:
|
||||
pitch_up(change_rate, jet)
|
||||
Globals.ControllerCommand.PITCH_DOWN:
|
||||
pitch_down(change_rate, jet)
|
||||
_:
|
||||
pass
|
||||
|
||||
match action.YAW:
|
||||
Globals.ControllerCommand.YAW_LEFT:
|
||||
yaw_left(change_rate, jet)
|
||||
Globals.ControllerCommand.YAW_RIGHT:
|
||||
yaw_right(change_rate, jet)
|
||||
Globals.ControllerCommand.ROLL_LEFT:
|
||||
roll_left(change_rate, jet)
|
||||
Globals.ControllerCommand.ROLL_RIGHT:
|
||||
roll_right(change_rate, jet)
|
||||
_:
|
||||
pass
|
||||
|
||||
if action.YAW == Globals.ControllerCommand.NONE:
|
||||
match action.ROLL:
|
||||
Globals.ControllerCommand.ROLL_LEFT:
|
||||
roll_left(change_rate, jet)
|
||||
Globals.ControllerCommand.ROLL_RIGHT:
|
||||
roll_right(change_rate, jet)
|
||||
_:
|
||||
pass
|
||||
|
||||
match action.THROTTLE:
|
||||
Globals.ControllerCommand.THROTTLE_UP:
|
||||
throttle_up(delta)
|
||||
Globals.ControllerCommand.THROTTLE_DOWN:
|
||||
|
||||
Reference in New Issue
Block a user