Hello there
It’s been some time now I’m noticing VERY , VERY odd behaviour from Physics.Raycast and Physics.Linecast
I am using the 3 parameters raycast, where parameter 1 is the origin, parameter 2 the direction and parameter 3 the maxDistance
Could anybody explain to me WHY when using this setup it says that my character is grounded at all time (even when flying in the air) BUT when I use the 4 parameters Raycast, my character is NO LONGER grounded?
Code that returns my character always grounded:
grounded = Physics.Raycast(infantryControllerGO.bottomBound + transform.up * 0.1f, -transform.up, 0.25f);
Code that works fine:
grounded = Physics.Raycast(infantryControllerGO.bottomBound + transform.up * 0.1f, -transform.up, out RaycastHit hit, 0.25f);
Screenshots of the 2 RaycastHit tooltips CLEARLY stating that parameter 3 is MaxDistance and not LAYER
That’s all for my rant
I’d still like an explanation to this nonsense
(My explanation is that there is one of the setup that doesn’t use the maxDistance but the layer, but then WHY the tooltips are wrong??)
EDIT: On Unity 2021.3.14f1 on MacOS
Just to be clear, I also tried it this way to be sure it wasn’t a parameter issue, even though I’m sure it’s not
grounded = Physics.Raycast(origin : infantryControllerGO.bottomBound + transform.up * 0.1f,
direction : -transform.up,
maxDistance : 0.25f);
While this works without any issues:
grounded = Physics.Raycast(origin : infantryControllerGO.bottomBound + transform.up * 0.1f,
direction : -transform.up,
out _groundedHit,
maxDistance : 0.25f);
Anyone from Unity would care to explain why the hell this system works the way it does?
Those 2 codes give two different outcomes, entirely
I’ll repeat it one more time, first version returns true all the time, second works as it should
The code is correct. I tested this and it worked as expected (with and without RaycastHit).
bool hitA = Physics.Raycast(origin, direction, distance);
bool hitB= Physics.Raycast(origin, direction, out RaycastHit hitInfo, distance);
print($"hit A= {hitA}, hit B= {hitB}");
What version of Unity are you using?
lightbug14:
The code is correct. I tested this and it worked as expected (with and without RaycastHit).
bool hitA = Physics.Raycast(origin, direction, distance);
bool hitB= Physics.Raycast(origin, direction, out RaycastHit hitInfo, distance);
print($"hit A= {hitA}, hit B= {hitB}");
What version of Unity are you using?
Thank you very much for testing this!
I am using Unity 2021.3.14f1 on MacOS