Question by Ptolemy2002
·
Oct 04, 2019 at 05:51 PM ·
linecast
Physics2D.LinecastAll returning false positive
I have the following code, used to check if the player is standing on top of the ground:
RaycastHit2D[] rays = Physics2D.LinecastAll(transform.position, groundCheck.position, layerMask: 1 << LayerMask.NameToLayer(groundLayer));
grounded = rays.Length >= 1;
The problem is that my variable "rays" always has a length of at least 1, even if the player is nowhere near an object on the ground layer. I checked in the log, and it appears that it always detects the platform at the bottom, which is always below the user, but the line shouldn't collide with that because it is too far below the user to be counted.
Comment