Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

maxDistance of Physics.Raycast to be object per layer

Discussion in 'Physics' started by LifeSymbiont, Nov 17, 2021.

  1. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36
    How do I set the maxDistance of a Physics.Raycast to be another object by layer?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Your question is far from clear. What does "another object by layer" mean.

    Maybe you mean performing a line (segment) test? Physics.Linecast ?
     
  3. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36
    That the MaxDistance ends where the hit of a raycast hits an object with a specific layer.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Yeah, that doesn't make it any clearer at all. How can you set the max-distance for a raycast based upon where it hits? You need the max-distance BEFORE you make the call so this cannot be what you mean.

    Nobody should have to guess what you mean and I cannot help you until you put some effort into explaining it better, sorry.
     
  5. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36
    This was actually what I meant, Thank you for the information that the max-distance happens before. This solved my question in a way.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    It doesn't "happen before", it's just an argument to a function you can call but still, I'm glad it sorted it for you but I'm honestly still confused on what was solved. :)