code (from the raycaster):
extends RayCast3D
@onready var hold_pos = $Hold_Position
@onready var is_held = false
@onready var old_pos
@onready var old_rot
func _physics_process(delta):
var collider = self.get_collider()
if collider != null:
var obj_col = collider.get_parent()
#print(obj_col)
if Input.is_action_just_pressed("player_interaction"):
print("player interaction") # print a message when the player interaction key is pressed
print("is_held: ", is_held) # print the value of is_held
if is_held == false and self.is_colliding():
print("if works!")
old_pos = obj_col.get_global_transform()
old_rot = obj_col.rotation_degrees
obj_col.get_parent().remove_child(obj_col)
hold_pos.add_child(obj_col)
obj_col.transform.origin = Vector3(0.8,1.2,-1)
obj_col.rotation_degrees = Vector3(0,0,0)
is_held = true
print("is_held after pick up: ", is_held) # print the value of is_held after pick up
elif is_held == true and Input.is_action_just_pressed("player_interaction"):
print("else works!")
var obj_col = hold_pos.get_child(0)
hold_pos.remove_child(obj_col)
get_tree().root.get_child(0).add_child(obj_col)
is_held = false