RaycastHit2D works incomprehensibly

for(int = 0; i < allPoints.Count; i++){
RaycastHit2D raycastHit2D = Physics2D.Raycast(transform.position, allPoints*.point);*
if (raycastHit2D.collider != null)
Debug.DrawRay(transform.position, raycastHit2D.point, Color.red);
Debug.Log(transform.position+" "+ allPoints*.point + " "+ raycastHit2D.point);*
log before change transform.position:
(0.0, 0.0, -15.2) (17.3, -10.0) (17.3, -10.0)
log after change transform.position:
(0.0, 8.0, -15.2) (17.3, -2.0) (17.3, 6.0)
For some strange reason, after changing the position of the object, the direction of the Ray2D shifts

Hey there,

well this can’t work since you are confusing positions of your points with directions.
You have to subtract all points by your transforms position to get a relative direction.
Currently your first ray direction is (17.3, -10.0). After moving it is (17.3, -2.0). → It does exactly what you tell it to do. Draw a ray in this direction.

hello, i think your issue is understanding Directions as Points. they are both Vector3 but they are not the same. when you are creating the ray, you are not passing points to the ray but directions. for example if you pass a direction to the ray that is

new Vector3(1,1);

the ray will go in the angle 45* and will have this angle anyway if the camera is at position (0,0,0) or position (0,8,0). so your issue will be fixed when you dont update the allPoints var, i imagine they are points in the editor so just leave them at the exat value, dont update it with the camera position since they are not points, but directions.

Indeed, I did not quite understand how it works. Now everything fell into place. Thanks!!!