What's the layermask for?

posted to: Adding Impact Force

So throughout the course you used a raymask and whatnot for a raycast, but I don't understand what the raymask is for. 

What does it do and why do I need it after already having specified that the Raycast is starting off the barrel tip, that it goes forward from there and how far it goes forward and that it should be drawn in a green colour? What does the raymask do exactly? Maybe I missed it from the previous videos.

  • Jonathan Gonzalez(jgonzalez) replied

     The layer mask is a way of determining what objects should be detected by the raycast. Without this the raycast will essentially detect all colliders. If you had a fairly complex scene and only wanted to detect say other players, your raycast would continually check against other objects and could be a performance drain. It can also be a great way to ignore your own colliders if you needed as well. 

    By specifying that you only want to check objects on a certain layer it ignores all the others and only detects the objects on that specified layer.


  • plasmavoyage replied

    Ah okay, makes sense now!

    Thank you very much, awesome course so far. I haven't done the turret exercise yet, because I like listening, but I will go through this entire course a second time anyways :)