Godot Version
Godot 4
Question
So I have a project I’m working on where there are items scenes loaded into the scene as soon as the game starts, but they are not in the scene during the editor (this is due to randomiser reasons, so that they spawn randomly). This all works fine, but now I want the player to be able to click on them and they know that they have been clicked on. The code below shows how it finds the collision shape, gets the parent (area 3d), get’s that parent’s parent (root node 3d) and emits the signal. then in the resource code (the script is a resource, if that needs clarification) it calls the function of the signal (i copied and pasted it there, since it’s not in the same scene on the editor). But… NOTHING HAPPENS. Please help, I have been banging my head against a walll for days and don’t know wwhat to do. This is the second project that I have worked on (i haven’t completed the first one) and I am feeling compeltely lost and overwhelmed.
If you share code, please wrap it inside three backticks or replace the code in the next block:
func shoot_ray():
var mouse_pos = get_viewport().get_mouse_position()
var ray_lenght = 1000
var from = project_ray_origin(mouse_pos)
var to = from + project_ray_normal(mouse_pos) * ray_lenght
var space = get_world_3d().direct_space_state
var ray_query = PhysicsRayQueryParameters3D.new()
ray_query.from = from
ray_query.to = to
var raycast_results = space.intersect_ray(ray_query)
print(raycast_results)
get_parent().get_parent()
emit_signal("mouse_hovering")