- Home /
Physics linecast ignoring layers
So basically I have this code:
RaycastHit collisionHit;
int layerMask = 1 << 8;
layerMask = ~layerMask;
Vector3 cameraTargetPosition = new Vector3(CameraTarget.position.x, CameraTarget.position.y + cameraTargetHeight, CameraTarget.position.z);
bool isCorrected = false;
if (Physics.Linecast(cameraTargetPosition, position, out collisionHit, layerMask))
{
position = collisionHit.point;
correctedDistance = Vector3.Distance(cameraTargetPosition, position);
isCorrected = false;
}
but I want to exclude layer 8 and 16 from linecast, so it doesn't hit the layer 8 and 16 all the time. It causes camera to zoom all the way into character and I want to avoid that by just excluding layer 8 which is layer for ragdoll colliders and layer 16 which is cloth collider.
How can I make NOT operator for layer to exclude both?
You should use a Layer$$anonymous$$ask. This also works good with RayCasts ( https://docs.unity3d.com/$$anonymous$$anual/Layers.html )
Well, I just need not operator to work and I doubt that's the solution.
Yes, I know, but i don't know a solution, and until someone posts an answer you could use a Layer$$anonymous$$ask ( https://docs.unity3d.com/ScriptReference/Layer$$anonymous$$ask.html ) and set the Layers in the inspector.
The bitwise OR operator is the 'pipe' so you can do
int layer$$anonymous$$ask = 1 << 8 | 1 << 16; // mask with bits 8 and 16 lit
layer$$anonymous$$ask = ~layer$$anonymous$$ask; // inverse: only bits 8 and 16 zero
Your answer
Follow this Question
Related Questions
Gravity not working when add animator layer 0 Answers
Layer Collision in Networks (Mulitplayer Game). 0 Answers
Make Certain Object's Raycasts Ignore Certain Colliders 0 Answers
How to add more than 31 Layers (maximum reached) 2 Answers
SplitScreen shooter with Viewmodels and PlayerModels without so many layers? 1 Answer