Search Unity

Proper way of setting areaMask int using code

Discussion in 'Scripting' started by nmizrahi, Feb 16, 2018.

  1. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    I'm trying to calculate a path specifying an areaMask I can't seem to make any sense of it.

    Using AllAreas works fine:

    NavMesh.CalculatePath(transform.position, targetObject.transform.position,NavMesh.AllAreas, path);

    If I have the following Areas set up, how would I specify the use the area "Road"?

    <See attached Image>

    If I manually set the area mask to "Road" and query it the int value is 16 but I don't understand how this is derived.

    Any help?

    I searched for documentation but did not find anything.

    Thank you.
     

    Attached Files:

  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If you're just asking why it's 16, it's because of the mask. 2^4 = 16, in your example.
    Is that what you wanted to know?
     
  3. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    In this case what does the 2 and the 4 represent?
     
  4. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    Oh I see, it's binary, reading from the end of the area mask list.

    010000, which is 16.

    Thank you.
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Yes, sorry :) Maybe I should have added that. heh.