Cleanup controller logic; tested more dot product stuff
This commit is contained in:
@@ -41,6 +41,6 @@ enum CompoundCommandType {
|
|||||||
|
|
||||||
class CompoundCommand:
|
class CompoundCommand:
|
||||||
var PITCH: int = ControllerCommand.NONE
|
var PITCH: int = ControllerCommand.NONE
|
||||||
var YAW: int = 0
|
var YAW: int = ControllerCommand.NONE
|
||||||
var ROLL: int = 0
|
var ROLL: int = ControllerCommand.NONE
|
||||||
var THROTTLE: int = 0
|
var THROTTLE: int = ControllerCommand.NONE
|
||||||
|
|||||||
+2
-10
@@ -19,23 +19,15 @@ var targeted_by: Jet = null
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
#var action: Globals.CompoundCommand = controller.process(delta)
|
|
||||||
#if action:
|
|
||||||
#control_frame.do_action(action, delta, self)
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
|
||||||
var action: Globals.CompoundCommand = controller.process(delta)
|
var action: Globals.CompoundCommand = controller.process(delta)
|
||||||
if action:
|
if action:
|
||||||
control_frame.do_action(action, delta, self)
|
control_frame.do_action(action, delta, self)
|
||||||
|
|
||||||
|
func _physics_process(_delta: float) -> void:
|
||||||
velocity = -transform.basis.z * control_frame.speed
|
velocity = -transform.basis.z * control_frame.speed
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
#func _unhandled_input(event: InputEvent) -> void:
|
|
||||||
#var action: Globals.CompoundCommand = controller.unhandled_input(event)
|
|
||||||
#if not action: return
|
|
||||||
|
|
||||||
func set_model(model: Node) -> void:
|
func set_model(model: Node) -> void:
|
||||||
add_child(model)
|
add_child(model)
|
||||||
|
|
||||||
|
|||||||
@@ -36,15 +36,16 @@ func process_jet_plan(jet: Jet) -> void:
|
|||||||
|
|
||||||
var target_local_position: Vector3 = jet.to_local(jet.target.global_position)
|
var target_local_position: Vector3 = jet.to_local(jet.target.global_position)
|
||||||
var target_direction: Vector3 = target_local_position.normalized()
|
var target_direction: Vector3 = target_local_position.normalized()
|
||||||
jet.target_ray.target_position = target_direction * 8
|
jet.target_ray.target_position = target_direction
|
||||||
|
|
||||||
#NOTE: When using unit (normalized) vectors, the result will always be
|
#NOTE: When using unit (normalized) vectors, the result will always be
|
||||||
# between -1.0 (180 degree angle) when the vectors are facing opposite
|
# between -1.0 (180 degree angle) when the vectors are facing opposite
|
||||||
# directions, and 1.0 (0 degree angle) when the vectors are aligned.
|
# directions, and 1.0 (0 degree angle) when the vectors are aligned.
|
||||||
|
|
||||||
var forward_dot: float = target_direction.dot(Vector3.UP)
|
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 lr_dot: float = target_direction.dot(Vector3.RIGHT)
|
||||||
print(rad_to_deg(cosh(forward_dot)))
|
|
||||||
|
jet.controller.cpu.yaw_left()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,19 +18,3 @@ func process(delta: float) -> Globals.CompoundCommand:
|
|||||||
return player.process(delta)
|
return player.process(delta)
|
||||||
_:
|
_:
|
||||||
return Globals.CompoundCommand.new()
|
return Globals.CompoundCommand.new()
|
||||||
|
|
||||||
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.CompoundCommand.new()
|
|
||||||
|
|
||||||
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.CompoundCommand.new()
|
|
||||||
|
|||||||
@@ -7,13 +7,6 @@ var commands: Globals.CompoundCommand = Globals.CompoundCommand.new()
|
|||||||
func process(_delta: float) -> Globals.CompoundCommand:
|
func process(_delta: float) -> Globals.CompoundCommand:
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
func physics_process(_delta: float) -> Globals.CompoundCommand:
|
|
||||||
return commands
|
|
||||||
|
|
||||||
func unhandled_input(_event: InputEvent) -> Globals.CompoundCommand:
|
|
||||||
return commands
|
|
||||||
|
|
||||||
|
|
||||||
func pitch_up() -> void:
|
func pitch_up() -> void:
|
||||||
commands.PITCH = Globals.ControllerCommand.PITCH_UP
|
commands.PITCH = Globals.ControllerCommand.PITCH_UP
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ func process(_delta: float) -> Globals.CompoundCommand:
|
|||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
func physics_process(_delta: float) -> Globals.CompoundCommand:
|
|
||||||
return Globals.CompoundCommand.new()
|
|
||||||
|
|
||||||
func unhandled_input(_event: InputEvent) -> Globals.CompoundCommand:
|
|
||||||
return Globals.CompoundCommand.new()
|
|
||||||
|
|
||||||
func no_action() -> void:
|
func no_action() -> void:
|
||||||
commands.PITCH = Globals.ControllerCommand.NONE
|
commands.PITCH = Globals.ControllerCommand.NONE
|
||||||
commands.YAW = Globals.ControllerCommand.NONE
|
commands.YAW = Globals.ControllerCommand.NONE
|
||||||
|
|||||||
+31
-30
@@ -1,40 +1,41 @@
|
|||||||
class_name TestWorld extends Node3D
|
class_name TestWorld extends Node3D
|
||||||
|
|
||||||
|
|
||||||
|
@onready var jet: Node3D = $jet
|
||||||
|
@onready var jet2: Node3D = $jet2
|
||||||
|
var target_ray: RayCast3D
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
target_ray = jet.get_node("target_ray")
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
var jet: Node3D = $jet
|
#test_dot_product(delta)
|
||||||
var jet2: Node3D = $jet2
|
pass
|
||||||
var target_ray: RayCast3D = jet.get_node("target_ray")
|
|
||||||
|
|
||||||
#var direction: Vector3 = (
|
|
||||||
#jet2.global_position - jet.global_position
|
|
||||||
#).normalized()
|
|
||||||
var target_direction = jet.to_local(jet2.global_position).normalized()
|
|
||||||
#var target_direction = jet.to_local(jet2.global_position)
|
|
||||||
|
|
||||||
target_ray.target_position = target_direction * 2
|
|
||||||
|
|
||||||
# NOTE: (From GPT) Mostly works but with precession nor do I really understand it...
|
|
||||||
#var forward_dot: float = target_direction.dot(Vector3.UP)
|
|
||||||
#print(forward_dot)
|
|
||||||
#print(jet.rotation.angle_to())
|
|
||||||
#print("Up: " + str((target_direction).dot(Vector3.UP)) )
|
|
||||||
print("Forward: " + str((target_direction).dot(Vector3.FORWARD)) )
|
|
||||||
|
|
||||||
|
|
||||||
|
func test_dot_product(_delta: float) -> void:
|
||||||
|
#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 target_local_position: Vector3 = jet.to_local(jet2.global_position)
|
||||||
|
var target_direction: Vector3 = target_local_position.normalized()
|
||||||
|
target_ray.target_position = target_direction
|
||||||
|
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)
|
||||||
|
|
||||||
|
#NOTE: if neg 'below'; if pos 'above'.
|
||||||
|
# Need window between +-0.2 or something for centered
|
||||||
|
print("Forward : ", forward_dot)
|
||||||
|
#print("Forward : ", rad_to_deg(cosh(forward_dot)))
|
||||||
|
|
||||||
|
#NOTE: if neg 'behind'; if pos 'ahead'.
|
||||||
|
# Need window between +-0.2 or something for centered
|
||||||
|
print("Up | Down : ", ud_dot)
|
||||||
|
#print("Up | Down : ", rad_to_deg(cosh(ud_dot)))
|
||||||
|
|
||||||
|
#NOTE: if neg 'left'; if pos 'right'.
|
||||||
# NOTE: (From GPT) Mostly works but with precession nor do I really understand it...
|
# Need window between +-0.2 or something for centered
|
||||||
#var forward_dot: float = target_direction.dot(Vector3.UP)
|
print("Left | Right : ", lr_dot)
|
||||||
#if forward_dot >= cos(deg_to_rad(37.5)):
|
#print("Left | Right : ", rad_to_deg(cosh(lr_dot)))
|
||||||
#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()
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, -2)
|
|||||||
mesh = SubResource("BoxMesh_530sk")
|
mesh = SubResource("BoxMesh_530sk")
|
||||||
|
|
||||||
[node name="jet2" type="Node3D" parent="."]
|
[node name="jet2" type="Node3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.4830952, 10.637592, -22.128391)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.668, 7.773, -22.128)
|
||||||
|
|
||||||
[node name="target_ray" type="RayCast3D" parent="jet2"]
|
[node name="target_ray" type="RayCast3D" parent="jet2"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user