immersive-home/app/content/system/house/align_reference.gd

68 lines
2.1 KiB
GDScript3
Raw Permalink Normal View History

2024-01-24 18:43:44 +02:00
extends Node3D
@onready var corner1 = $Corner1
@onready var corner2 = $Corner1/Corner2
@onready var edge = $Edge
@onready var marker = $Edge/Marker3D
@export var disabled: bool:
set(value):
disabled = value
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): return
corner1.get_node("CollisionShape3D").disabled = disabled
corner2.get_node("CollisionShape3D").disabled = disabled
edge.get_node("CollisionShape3D").disabled = disabled
corner1.visible = !disabled
corner2.visible = !disabled
edge.visible = !disabled
2024-01-24 18:43:44 +02:00
func _ready():
2024-05-22 19:38:28 +03:00
update_initial_positions.call_deferred()
2024-01-24 18:43:44 +02:00
corner1.get_node("Movable").on_move.connect(func(position, rotation):
edge.align_to_corners(corner1.global_position, corner2.global_position)
)
corner2.get_node("Movable").on_move.connect(func(position, rotation):
edge.align_to_corners(corner1.global_position, corner2.global_position)
2024-01-29 13:37:25 +02:00
corner2.look_at(corner1.global_position, Vector3.UP)
2024-03-21 14:29:10 +02:00
corner2.rotate(Vector3.UP, deg_to_rad( - 90))
2024-01-24 18:43:44 +02:00
)
corner2.get_node("Movable").restrict_movement = func(new_position):
new_position.y = corner1.global_position.y
var delta_new_pos_corner1 = (new_position - corner1.position).normalized()
return corner1.position + delta_new_pos_corner1
func update_initial_positions():
2024-05-22 19:38:28 +03:00
if App.main.is_node_ready() == false:
await App.main.ready
2024-01-24 18:43:44 +02:00
edge.align_to_corners(corner1.global_position, corner2.global_position)
2024-05-22 19:38:28 +03:00
marker.global_transform = App.house.transform
2024-01-24 18:43:44 +02:00
2024-01-29 13:37:25 +02:00
func get_new_transform():
2024-01-24 18:43:44 +02:00
marker.scale = Vector3(1, 1, 1)
return marker.global_transform
2024-01-25 17:29:33 +02:00
func update_align_reference():
2024-04-09 18:46:59 +03:00
corner1.global_position = Store.house.state.align_position1
corner2.global_position = Store.house.state.align_position2
2024-04-26 15:42:30 +03:00
if corner1.global_position == corner2.global_position:
corner2.global_position = corner1.global_position + Vector3(1, 0, 0)
2024-01-25 17:29:33 +02:00
2024-01-29 13:37:25 +02:00
corner2.look_at(corner1.global_position, Vector3.UP)
2024-03-21 14:29:10 +02:00
corner2.rotate(Vector3.UP, deg_to_rad( - 90))
2024-01-29 13:37:25 +02:00
2024-01-25 17:29:33 +02:00
edge.align_to_corners(corner1.global_position, corner2.global_position)
func update_store():
2024-04-09 18:46:59 +03:00
Store.house.state.align_position1 = corner1.global_position
2024-05-22 19:38:28 +03:00
Store.house.state.align_position2 = corner2.global_position