I have two raycasts2D, each going opposite directions to get the entry and exit points of a bullet. Here is their code:
RaycastHit2D[] Hits = Physics2D.RaycastAll(NearGunRange.transform.position, LookDirection, MaxRange);
RaycastHit2D[] Hits2 = Physics2D.RaycastAll(FarGunRange.transform.position, -LookDirection, MaxRange);
Debug.DrawRay(NearGunRange.transform.position, LookDirection * 50, Color.red);
Debug.DrawRay(FarGunRange.transform.position, -LookDirection * 50, Color.red);
The Near and Far GunRange gameObjects are both parented to the player. The Near one has transform poisiotn of 0, 0, 0, and the far one has transform position of 0, 40, 0. I get the LookDirection from this code:
RightHorizontalInput = Input.GetAxisRaw("RightStickHorizontal");
RightVerticalInput = Input.GetAxisRaw("RightStickVertical");
LookDirection = new Vector2(RightHorizontalInput, RightVerticalInput);
From this code I expected that the two raycasts would always overlap each other, but they don’t. They are both parellel to each other but they are offset from each other and they both stutter. Here is a video for example: