Quantcast
Viewing all articles
Browse latest Browse all 99

Answer by ThePersister

Using a LayerMask is your best way out of this one. As mentioned before but not replied to yet. I quote:> *I tried using the separate layer, and*> *it didn`t work.*>> *If I use this, will the layer named*> *IgnoreTHis be ignored or only this*> *layer will get detected? (Syntax may*> *be wrong its just an example)*>>> RaycastHit2D hit = Physics2D.Raycast(transform.position,> direction,> Mathf.Infinity,> LayerMask.NameToLayer("IgnoreTHis")); The layer you put in the Layermask parameter **WILL BE THE ONLY ONE HIT**. :3 If you wish to ignore a layer instead, you can invert the layermask using a Squiggly ~ operator. Not checking on the syntax either, but basically like this: RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, Mathf.Infinity, ~LayerMask.NameToLayer("IgnoreThis")); In the above code, the Raycast will hit everything BUT the layer "IgnoreThis". Cool tip, you can store a: public LayerMask IgnoreLayer; Which will allow you to easily select a cool layer in the inspector, getting rid of some dirty code, and making it much nicer to update, especially if you use the Layermask in multiple places. :) I hope that helps. If this answer is satisfactory, please accept it. If not, I'll be awaiting more questions / details :3 Best of luck! Yours truly, ~ThePersister

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>