Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MemokingMH |
onready var raycast = get_node(“RayCast”)
var held_item
if event.is_action_pressed(“interact”) and item_in_range:
held_item = raycast.get_collider()
var instance = held_item.instance()
held_item.queue_free()
hand.add_child(instance)
This is my code. “Invalid call. Nonexistent function ‘instance’ in base 'StaticBody (Pot.gd).” is the error it gives. “item_in_range” becomes true when raycast collides with an object(I tested this with print method it works fine). I want to destroy the object I’m looking at and create an instance of it in my hand. What is the problem with this code and is there a better way of doing this. I’ve been using godot for a fair bit of time but this is my first time looking into 3d so I don’t get most diffrences and try to do things in same way I did in 2d so I’m sure this isn’t the most efficient code.