Throw item if placement preview is invalid

main
copygirl 2 years ago
parent c4324182ec
commit 3ac59f082e
  1. 22
      scripts/PickupController.gd

@ -49,13 +49,23 @@ func _input(event: InputEvent) -> void:
is_current_item_held = false
# 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)
world.add_child(current_item)
# Set item's transform to where the placement preview is.
# TODO: If placement preview is not valid, don't allow placing the item.
current_item.global_transform = placement_preview.global_transform
current_item.freeze = false
# If placement is valid, move item to the preview's location.
# Otherwise just restore the transform of where it was held.
if placement_preview.visible:
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 = null
@ -89,6 +99,10 @@ func _physics_process(_delta: float) -> void:
pos += half_size * (normal * placement_preview.global_transform.basis)
pos = pos.snapped(Item.GRID_SIZE * Vector3.ONE)
placement_preview.global_position = pos
placement_preview.visible = true
else:
placement_preview.visible = false
else:
# Remove the outline from the previously looked-at item.

Loading…
Cancel
Save