2023-11-05 22:32:50 +02:00
|
|
|
@tool
|
|
|
|
extends Function
|
|
|
|
class_name Movable
|
|
|
|
|
2024-01-16 16:00:30 +02:00
|
|
|
@export var restricted: bool = false
|
|
|
|
@export var lock_rotation: bool = false
|
2023-11-06 16:39:53 +02:00
|
|
|
var hit_node := Node3D.new()
|
2023-11-05 22:32:50 +02:00
|
|
|
|
2023-11-27 01:23:19 +02:00
|
|
|
func _on_grab_down(event: EventPointer):
|
2024-01-16 16:00:30 +02:00
|
|
|
if restricted && event.target != get_parent():
|
|
|
|
return
|
|
|
|
|
2023-11-27 01:23:19 +02:00
|
|
|
event.initiator.node.add_child(hit_node)
|
2023-11-14 01:51:48 +02:00
|
|
|
hit_node.global_transform = get_parent().global_transform
|
2023-11-05 22:32:50 +02:00
|
|
|
|
2023-11-27 01:23:19 +02:00
|
|
|
func _on_grab_move(_event: EventPointer):
|
2024-01-16 16:00:30 +02:00
|
|
|
get_parent().global_position = hit_node.global_position
|
|
|
|
|
|
|
|
if !lock_rotation:
|
|
|
|
get_parent().global_rotation = hit_node.global_rotation
|
2023-11-14 01:51:48 +02:00
|
|
|
|
2023-11-27 01:23:19 +02:00
|
|
|
func _on_grab_up(event: EventPointer):
|
|
|
|
event.initiator.node.remove_child(hit_node)
|
2023-11-05 22:32:50 +02:00
|
|
|
|
|
|
|
func _get_configuration_warnings() -> PackedStringArray:
|
|
|
|
var warnings := PackedStringArray()
|
|
|
|
|
|
|
|
if get_parent() is StaticBody3D == false:
|
|
|
|
warnings.append("Movable requires a StaticBody3D as parent.")
|
|
|
|
|
|
|
|
|
2023-11-06 16:39:53 +02:00
|
|
|
return warnings
|