print an output when I point a certain object with the crosshair (camera)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zqwerty

hi guys, i’m stuck.
I’m creating a sort of first-person 3d fps, where I move the camera son wasd and the view with the mouse (I also inserted a crosshairin the camera), I have the main scene and inside it I have the final scene (the map) and the scene player (the camera object is located here).
when I point a certain object with the crosshair I would like to display an output (like a printf) but I can’t.
I have seen that I should use the signals but I cannot understand how, also with the mouse pointer I can do it but with the crosshair not

:bust_in_silhouette: Reply From: Legorel

You could add a raycast node at the player’s eye and in the _process or _physics_proccess you would do this:

var raycast = $Path/To/Raycast/Node

func _physics_process():
  if raycast.is_colliding():
    var object = raycast.get_collider()
    print(object.name)