Cleaned up notes; restructured test scene plus cpu controller script; added WIP action stack logic
This commit is contained in:
+71
-14
@@ -1,41 +1,98 @@
|
||||
class_name TestWorld extends Node3D
|
||||
|
||||
|
||||
@onready var jet: Node3D = $jet
|
||||
@onready var jet2: Node3D = $jet2
|
||||
var target_ray: RayCast3D
|
||||
@onready var jet: Node3D = $jet
|
||||
@onready var jet2: Node3D = $jet2
|
||||
@onready var marker: Marker3D = $marker
|
||||
@onready var ray: RayCast3D = $ray
|
||||
@onready var target_ray: RayCast3D = $jet/target_ray
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
target_ray = jet.get_node("target_ray")
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
#test_dot_product(delta)
|
||||
pass
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
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
|
||||
manual_direction_and_length()
|
||||
var target_direction = tool_direction_and_length()
|
||||
|
||||
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)
|
||||
#var rotation_dot = jet.rotation.direction_to().normalized().dot(Vector3.FORWARD)
|
||||
var rotation_dot = clampf(jet.rotation_degrees.z / 360.0, -1, 1)
|
||||
|
||||
#NOTE: if neg 'below'; if pos 'above'.
|
||||
# Need window between +-0.2 or something for centered
|
||||
print("Forward : ", forward_dot)
|
||||
#print("Rotation : ", rotation_dot)
|
||||
#print("Rotation : ", rad_to_deg(cosh(rotation_dot)))
|
||||
|
||||
#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 : ", ud_dot)
|
||||
#print("Up | Down : ", rad_to_deg(cosh(ud_dot)))
|
||||
|
||||
#NOTE: if neg 'left'; if pos 'right'.
|
||||
# Need window between +-0.2 or something for centered
|
||||
print("Left | Right : ", lr_dot)
|
||||
#print("Left | Right : ", lr_dot)
|
||||
#print("Left | Right : ", rad_to_deg(cosh(lr_dot)))
|
||||
|
||||
|
||||
func tool_direction_and_length() -> Vector3:
|
||||
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
|
||||
|
||||
return target_direction
|
||||
|
||||
func manual_direction_and_length() -> void:
|
||||
# NOTE: Length is treated as length of a vector.
|
||||
# Distance is a length between two points aquired by the 'difference vector' which to get is (to_vec - from_vec)
|
||||
# VERY important to be to/from rather than from/to as from/to would give direction from target position than self
|
||||
# To do the manual equivilint of:
|
||||
# var target_direction: Vector3 = jet.to_local(jet2.global_position).normalized()
|
||||
# We do:
|
||||
# var target_direction: Vector3 = (
|
||||
# (jet2.global_position - jet.global_position)
|
||||
# /
|
||||
# (jet2.global_position - jet.global_position).length()
|
||||
# ) + jet.global_position
|
||||
# Like so:
|
||||
|
||||
var target_direction_difference: Vector3 = (jet2.global_position - jet.global_position)
|
||||
# NOTE: Length is the square root of the sum of the squared components
|
||||
# length = sqrt(x^2 + y^2 + z^2) // Single vector length; note, could just be x,y if in 2D
|
||||
# combined vectors way:
|
||||
# length = sqrt( (b.x - a.x)^2 + (b.y - a.y)^2 + (b.z - a.z)^2 )
|
||||
var target_direction_length: float = sqrt(
|
||||
pow(target_direction_difference.x, 2.0)
|
||||
+ pow(target_direction_difference.y, 2.0)
|
||||
+ pow(target_direction_difference.z, 2.0)
|
||||
)
|
||||
|
||||
# NOTE: Could divide by zero. Handle with exception or return 0,0,0 as we do here
|
||||
var target_direction_normalized: Vector3 = \
|
||||
(target_direction_difference / target_direction_length) \
|
||||
if target_direction_length > 0.0 else Vector3.ZERO
|
||||
|
||||
ray.global_position = jet.global_position
|
||||
# ray is in local space context so giving direction just works
|
||||
ray.target_position = target_direction_normalized
|
||||
|
||||
# corrected position b/c target_global_direction starts at 0,0,0 globally.
|
||||
# (normalized not a factor other than affecting length)
|
||||
# thus add 'jet' position to move origin to it + resulting offset
|
||||
var target_direction = target_direction_normalized + jet.global_position
|
||||
marker.global_position = target_direction
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=15 format=3 uid="uid://boihqkqrbm0ti"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://boihqkqrbm0ti"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://emw28v4vimpy" path="res://skunk_works/test_world.gd" id="1_nnwr0"]
|
||||
[ext_resource type="PackedScene" uid="uid://bhjfvc7gkrvah" path="res://base_environment.tscn" id="2_iba6n"]
|
||||
@@ -51,6 +51,14 @@ emission = Color(0, 0.18431373, 0.4745098, 1)
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_530sk"]
|
||||
material = SubResource("StandardMaterial3D_ggpwi")
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_530sk"]
|
||||
albedo_color = Color(0.7921569, 0, 0, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(0.7921569, 0, 0, 1)
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_gwly4"]
|
||||
material = SubResource("StandardMaterial3D_530sk")
|
||||
|
||||
[node name="test_world" type="Node3D"]
|
||||
script = ExtResource("1_nnwr0")
|
||||
|
||||
@@ -113,6 +121,15 @@ mesh = SubResource("BoxMesh_ggpwi")
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, -2)
|
||||
mesh = SubResource("BoxMesh_530sk")
|
||||
|
||||
[node name="ray" type="RayCast3D" parent="."]
|
||||
|
||||
[node name="marker" type="Marker3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -15.739372)
|
||||
|
||||
[node name="dot" type="MeshInstance3D" parent="marker"]
|
||||
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.01133728, 0, 0)
|
||||
mesh = SubResource("SphereMesh_gwly4")
|
||||
|
||||
[node name="camera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(0.45554495, -0.23939586, 0.8574196, 0, 0.96316254, 0.26891983, -0.8902128, -0.12250507, 0.43876383, 20.807, 12.386, 0.178)
|
||||
transform = Transform3D(0.6978729, -0.025204023, 0.71577805, 0, 0.99938065, 0.03519026, -0.71622163, -0.024558326, 0.6974406, 8.063868, 1.6829107, 1.3785272)
|
||||
current = true
|
||||
|
||||
Reference in New Issue
Block a user