func Player_is_in_LOS():
var space = get_world_2d().direct_space_state
var LOS_obstacle = space.intersect_ray(global_position, Player.global_position, [self], collision_mask)
if LOS_obstacle.collider == Player and (Player.global_position.distance_to(global_position) < MAX_DETECTION_RANGE):
return true
else:
return false
Same code just a few less variables.