RayCast in 3D not moving as I wish it would

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

Hi all, I’m trying to create a 3rd person camera, and I’m using RayCast to detect occlusions, but the RayCast movement is not smooth

Here are two gifs showing how it looks, from the camera perspective, and from a second camera perspective, for reference:

Basically the ray moves up and down, not following the exact center of the camera
And here is the code:

var raycast = get_node("RayCast")
raycast.visible = true
raycast.enabled = true
raycast.cast_to = $Camera.translation

Anyone has any tips?