|
|
@ -49,13 +49,23 @@ func _input(event: InputEvent) -> void: |
|
|
|
is_current_item_held = false |
|
|
|
is_current_item_held = false |
|
|
|
|
|
|
|
|
|
|
|
# Parent item back to the world. |
|
|
|
# Parent item back to the world. |
|
|
|
|
|
|
|
var prev_transform := current_item.global_transform |
|
|
|
|
|
|
|
current_item.freeze = false |
|
|
|
|
|
|
|
# FIXME: Item appears to just float after unfreezing. |
|
|
|
|
|
|
|
|
|
|
|
remove_child(current_item) |
|
|
|
remove_child(current_item) |
|
|
|
world.add_child(current_item) |
|
|
|
world.add_child(current_item) |
|
|
|
|
|
|
|
|
|
|
|
# Set item's transform to where the placement preview is. |
|
|
|
# If placement is valid, move item to the preview's location. |
|
|
|
# TODO: If placement preview is not valid, don't allow placing the item. |
|
|
|
# Otherwise just restore the transform of where it was held. |
|
|
|
current_item.global_transform = placement_preview.global_transform |
|
|
|
if placement_preview.visible: |
|
|
|
current_item.freeze = false |
|
|
|
current_item.global_transform = placement_preview.global_transform |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
current_item.global_transform = prev_transform |
|
|
|
|
|
|
|
# Throw item forward and up a bit. |
|
|
|
|
|
|
|
var cam_basis := camera.global_transform.basis |
|
|
|
|
|
|
|
var direction := -cam_basis.z + cam_basis.y |
|
|
|
|
|
|
|
current_item.apply_impulse(direction * 2) |
|
|
|
|
|
|
|
|
|
|
|
placement_preview.queue_free() |
|
|
|
placement_preview.queue_free() |
|
|
|
placement_preview = null |
|
|
|
placement_preview = null |
|
|
@ -89,6 +99,10 @@ func _physics_process(_delta: float) -> void: |
|
|
|
pos += half_size * (normal * placement_preview.global_transform.basis) |
|
|
|
pos += half_size * (normal * placement_preview.global_transform.basis) |
|
|
|
pos = pos.snapped(Item.GRID_SIZE * Vector3.ONE) |
|
|
|
pos = pos.snapped(Item.GRID_SIZE * Vector3.ONE) |
|
|
|
placement_preview.global_position = pos |
|
|
|
placement_preview.global_position = pos |
|
|
|
|
|
|
|
placement_preview.visible = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
placement_preview.visible = false |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
# Remove the outline from the previously looked-at item. |
|
|
|
# Remove the outline from the previously looked-at item. |
|
|
|