So I’ve been working in Unity for about a year now, and I just went back to do some raycasting the way I usually do, and then I see this:
I’ve never seen this QueryTriggerInteraction stuff before, and I no longer see a spot to put any kind of RaycastHit. I’ve tried this with Linecast, Raycast, and RaycastAll. It all does the same thing.
What’s going on? Is Unity trying to get rid of (or has gotten rid of) RaycastHits? How do I do this guys?
Just use something like
public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
or
public static bool Raycast(Ray ray, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
In manual Physics.Raycast there are overloads that have out RaycastHit hitInfo
like I’ve listed above, it’s just they’re not on top so you have to scroll page down. Your MonoDevelop/VS codehint should have them as well as those that don’t have RaycastHit.
Example:
Ray ray = new Ray();//Replace this with proper ray obviously
RaycastHit hitInfo;
if(Physics.Raycast(ray, out hitInfo))
{
//We hit something, so do something. What we hit is in hitInfo.
}
Specifically in your case call is as Physics.Raycast(ray, out hitInfo, 100.0f, lm_GravityZoneMask);
Linecast has overload like that too: Physics.Linecast(start,end,out hitInfo);
I don’t know what’s problem with RaycastAll as manual states it still returns RaycastHit and my VS sais same.
QueryTriggerInteraction defines whether this raycast should hit isTrigger colliders or not. By default it uses global setting (Physics.queriesHitTriggers).