Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
geckoo

LayerMask + Physics.Linecast

Question

This is a fact - I don't understand anything about layer when I use a RaycastHit or a Linecast. I have a layer which is defined using the integer 8. Creating a Linecast between two objects, I want to ignore this layer, but I have no clue how I can code it. I tried to find some clear explanation on the web, but I am strugling hard. My code doesn't work as I expected. Have you an idea please? Thank you ++

Please login or register to see this code.

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Instead of messing with integers to layermask, why not just use a layermask to begin with and just pick the layers you want it to affect in the inspector?:

 

public LayerMask mask;

 

if(!Physics.LineCast(direction, position, mask))

 

edit: FYI, whatever is unchecked it will ignore

  • Like 1

Share this post


Link to post
Share on other sites

  • 0

Great idea. It works fine. Often I use a second camera for weapon or something else, setting different layers, but I forgot it. Thank you OcularCash for your help ++

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...