Cleanup controller logic; tested more dot product stuff
This commit is contained in:
+31
-30
@@ -1,40 +1,41 @@
|
||||
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:
|
||||
var jet: Node3D = $jet
|
||||
var jet2: Node3D = $jet2
|
||||
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)) )
|
||||
#test_dot_product(delta)
|
||||
pass
|
||||
|
||||
|
||||
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: (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()
|
||||
#NOTE: if neg 'left'; if pos 'right'.
|
||||
# Need window between +-0.2 or something for centered
|
||||
print("Left | Right : ", lr_dot)
|
||||
#print("Left | Right : ", rad_to_deg(cosh(lr_dot)))
|
||||
|
||||
Reference in New Issue
Block a user