Doing test and cant understand why am i not getting the correct result. Result is off by about 0.2 units in Y axis
extends Node3D
@onready var node_3d_bottom: Node3D = $Node3D_bottom
@onready var node_3d_2_top: Node3D = $Node3D2_top
@onready var node_3d_3_plane: Node3D = $Node3D3_plane
@onready var node_3d_2_top_2: Node3D = $Node3D2_top2
var global_aabb:AABB
var local_aabb:AABB
var arr_y = []
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var mt:MeshInstance3D = node_3d_2_top_2.get_children()[0]
global_aabb= node_3d_2_top_2.global_transform * mt.get_aabb()
local_aabb = mt.get_aabb()
var arr = []
for i in range(8):
var pt = local_aabb.get_endpoint(i)
var pt_glob = mt.to_global(pt)
arr.append(pt_glob)
for p in arr:
arr_y.append(p.y)
print("pos: ",global_aabb.position)
print("siz: ",global_aabb.size)
print("end: ",global_aabb.end)
print("top node: ",node_3d_3_plane.global_position)
print("arr: ",arr)
print("arr_y: ",arr_y)
print("arr_y max: ",arr_y.max())
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
node_3d_3_plane.global_position.y = lerp(node_3d_3_plane.global_position.y,arr_y.max(),0.8*delta)
pass
The red plane is lerping towards the arr_y.max() value which is 4.22, same value is from the global_aabb= node_3d_2_top_2.global_transform * mt.get_aabb()
where the resulted .end vector Y axis is at 4.22. But placing the red plane along the Y axis to the end of the bounding box is at 4.40
STD: @ ready
pos: (-0.772845, 2.689352, -1.050277)
siz: (1.54569, 1.536256, 1.723653)
end: (0.772845, 4.225608, 0.673377)
top node: (0, 0, 0)
arr: [(-0.003363, 3.372365, 0.673377), (-0.162882, 4.225608, 0.176858), (-0.613326, 2.891711, 0.043362), (-0.772845, 3.744954, -0.453156), (0.772845, 3.170006, 0.076256), (0.613326, 4.023249, -0.420262), (0.162882, 2.689352, -0.553757), (0.003363, 3.542595, -1.050277)]
arr_y: [3.37236499786377, 4.22560787200928, 2.89171099662781, 3.74495387077332, 3.17000603675842, 4.02324867248535, 2.68935203552246, 3.54259490966797]
arr_y max: 4.22560787200928
not sure why am i not getting that 4.4 Y as the largest size.