issues updating variable using 'get_world_3d().direct_space_state'

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

Hello there!

I’m making a rather simple 3d game where i need the player to be aimed at the mouse.
This works for a while, however once i move too far away it stops working.
here is my code in use:

func _physics_process(delta):
ProcessInput(delta) #we get the input of the player
ProcessMovement(delta) #we move the player according to our input

func ProcessInput(delta):
#raycast section to look for mouse coordinate in 3d
var space_state = get_world_3d().direct_space_state
#get mouse position
var mouse_position = get_viewport().get_mouse_position()
var params =
params.from = camera.project_ray_origin(mouse_position) #sets ray origin = camera.project_ray_normal(mouse_position)*10000 # sets ray max distance
params.exclude = []
params.collision_mask = 2 #only seek collision with the right collision mask
var result = space_state.intersect_ray(params)
if result:
	lookTarget = result.position
	print("Hit at point: ", result.position)

an image of how this code looks in godot

to give some more context: my player scene has a collision box attached that moves with it. I can see this box moving along accordingly so it is not a hierarchy based problem i think.
This is easily visible when i start my player high up in the air. it is responsive at first, but after falling so far the camera cannot render the original location of the box, i cannot rotate my player anymore.
this leads me to think the issue lies with the ‘var space_state = get_world_3d().direct_space_state’ line.
It gets triggered once and never updates afterwards. Neither do i find a way to clear and reset it - i thought it would already run every time the processinput() is called, but clearly i am wrong.

:bust_in_silhouette: Reply From: RohanLockley

Stepping away from the computer was a good idea. when I came back I put the option to see collisions on, and i found out that even though the mesh and object looked like they were translated, the collision box itself stayed behind. I fixed it simply by making the node in charge of detecting the raycast its own separate scene, and using a somple script that sets its translation offset to the player’s camera.