Files
PacketsPlease/packet_picker.gd

57 lines
1.9 KiB
GDScript

extends Node3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
var last_highlight = null;
var holding_object = null;
var last_action_object = null;
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
if holding_object == null:
if last_highlight != null:
last_highlight.HIGHLIGHT = false
last_highlight = null
if $RayCast3D.is_colliding():
$RayCast3D.get_collider().get_parent_node_3d().HIGHLIGHT = true
last_highlight = $RayCast3D.get_collider().get_parent_node_3d()
# Action Ray:
if $ActionRay.is_colliding():
$ActionRay.get_collider().highlight(true)
last_action_object = $ActionRay.get_collider()
elif last_action_object != null:
last_action_object.highlight(false);
last_action_object = null
pass
var packet_container_scene = preload("res://packet_container.tscn")
func _input(event):
if event.is_action_pressed("action") && last_highlight != null && holding_object == null:
var packet_container = last_highlight.get_parent_node_3d()
packet_container.remove_packet(last_highlight)
#last_highlight.queue_free()
$HoldPosition.add_child(last_highlight)
last_highlight.position = Vector3(0,0,0)
holding_object = last_highlight
if event.is_action_pressed("action") && last_action_object != null:
last_action_object.action()
if event.is_action_pressed("drop_action") && holding_object != null:
#$RotationHelper/XRCamera3D/HoldPosition/HoldPacketCollission.set_collision_layer(0)
var drop = packet_container_scene.instantiate()
drop.global_transform = holding_object.global_transform
$HoldPosition.remove_child(holding_object)
drop.add_child(holding_object)
#drop.set_collision_layer(1)
drop.set_collision_mask(1)
drop.gravity_scale = 1
drop.packet = holding_object
add_child(drop)
holding_object = null