I'm trying to figure out how to cast a ray in the direction the player is facing and place an icon on the surface the ray intersects with. I was following this tutorial and trying to get similar results to what's in the tutorial:


However, due to the age of the video, I'm guessing things are broken/changed. After poking around the documentation a bit, I came up with this:

extends CharacterBody3D

var input
var collision

# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.
func _physics_process(delta):
    #if Input.is_action_pressed("fire"):
    var direct_state = get_world_3d().direct_space_state
    var query = PhysicsRayQueryParameters3D.create(transform.origin, Vector3(0,0,20))
    var collision = direct_state.intersect_ray(query)

    if collision:
        print (collision.position)

Initially, I was trying to make the script output the coordinates of the collision on the left mouse button click, but commented that out to see if that was the problem or not. Even though I think this script should continuously output the coordinates as I move around in space, it's not doing so. I'm a bit at a loss to discern what piece of code I'm missing -- the documentation is definitely useful, but also overwhelming at first and I'm not entirely certain which piece I'm missing.

The (probably) obvious disclaimer that I am new to Godot and really fumbling here, so please be nice. If you could also explain my mistake or even just direct me to the specific documentation page that would clear up my confusion, that would be fantastic. Thanks in advance!