Timeline for Why is Raycast hitting a masked layer?
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 15, 2015 at 20:12 | vote | accept | Leggy7 | ||
Oct 15, 2015 at 20:12 | comment | added | Leggy7 | Now, at home, I tried it. Shame on me, it works perfectly. I got fooled by the fact that no compilers errors occurred giving overload with 3rd parameter as LAyerMask insted of float: I assumed such overload existed. Instead, apparently, unity can convert a LayerMask to a float implicitly. Thank you Gregory,your answer is correct! | |
Oct 15, 2015 at 13:51 | comment | added | DMGregory♦ |
Also, @Leggy7, I can't find the overload that you describe. In both Unity 4 & 5, Physics2D.Raycast reports only the one definition, with its various optional parameters, and distance always comes before layerMask. Physics.Raycast (the 3D version) does have an overload that takes (ray, distance, layerMask) which is the only 3-argument version I can find containing layerMask, but even there distance comes first.
|
|
Oct 15, 2015 at 12:09 | comment | added | DMGregory♦ | I've explained how the LayerMask type can in fact be mismatched for a float. Try it — the compiler might not be using the overload that you think it should. I've had this happen in my own code too. | |
Oct 15, 2015 at 8:10 | comment | added | Leggy7 | Thank you gregory but I think this is wrong. For a simple reason which is that layerMask in my raycast function is a LayerMask and cannot be mismatched for a float. Simply unity has overload for Raycasy(vector, vector, LayerMask) | |
Oct 13, 2015 at 20:35 | history | answered | DMGregory♦ | CC BY-SA 3.0 |