if (movement != Vector3.zero) { LayerMask myMask = 1 << 8; if (!Physics.Raycast(this.transform.position + Vector3.up, transform.forward, 1f)) { _playerAnimator.SetBool("Walk", true); } else { _playerAnimator.SetBool("Walk", false); } _playerRigidbody.MovePosition(transform.position + movement); this.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized), 4 * Time.deltaTime); } else { _playerAnimator.SetBool("Walk", false); } } 

enter image description here

I want this Raycast to not respond to triggers. For this, I created a separate layer (N9). Here, everything seems to be normal and the syntax is not broken, but nevertheless the object that uses this script does not respond at all. Can you help please.

    2 answers 2

    You may have set the mask (by the way, you set it incorrectly), and where do you use it?

     LayerMask myMask = 1 << 8; if (!Physics.Raycast(this.transform.position + Vector3.up, transform.forward, 1f, ?где маска?)) { ... } 

    To ignore layer 9, you need to set a mask like this: LayerMask myMask =! (1 << 9);

    1. 1 << 9 -> 10_0000_0000 - the mask indicates only the 9th layer
    2. ~(1 << 9) -> 01_1111_1111 - the mask indicates all layers except the 9th

    To reykast took into account the mask, and did not use the default, we write:

     LayerMask myMask = ~(1 << 9); if (!Physics.Raycast(this.transform.position + Vector3.up, transform.forward, 1f, myMask)) { ... } 

    In general, for such cases there is a special parameter QueryTriggerInteraction , which allows you to ignore any triggers at all:

     Physics.Raycast( this.transform.position + Vector3.up, transform.forward, 1f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore ) 
    • LayerMask myMask =! (1 << 8); Rider emphasizes this line, writes that! not applicable to int. - Andrew K.
    • @AndrewK. My mistake corrected the answer - RiotBr3aker 7:08 pm
    • Hmmm ... weird, still not working. Still takes into account the trigger. - Andrew K.
    • @AndrewK., And you hang at least on an object with a 9th layer trigger? - RiotBr3aker
    • Yes, of course, immediately checked. - Andrew K.

    Make it easier, LayerMask variable in your public component, and use the comparison with the variable already configured through the editor. Write the mask number in the code is not gud. If you later need to replace the layer or make a more complex mask from a combination of several layers, you simply make the setting through the editor without editing the code.