How to make an interaction icon?

Godot Version



I’m playing around wih making a first person game, and i want to make it so that an icon appears on screen whenever you’re looking at an object that can be interacted with and you’re in range to interact with it. The best example i can find this being done in is Cruelty Squad, with the green hand that pops up. Any help?

You can add a raycast as a child of the camera and have it cast outward from the camera.
Then you can add a CanvasLayer and a Sprite2D as a child of it with the icon you want.
For any object you want to be interacted with you can add it to a group called “interact”.

Then you will set up your code like:

func _physics_process(delta):
    if PATH_TO_RAYCAST.is_colliding():
        if PATH_TO_RAYCAST.get_collider().is_in_group("interact"):
            PATH_TO_ICON.visible = true
        PATH_TO_ICON.visible = false