How Does RayCast2D's "add_exception( )" Works?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Matt101

Hey everyone, i just wanna know how can i use the “add_exception” method from a RayCast2D node, and how does it work. I couldn’t find much stuff about it, so i wanna know from you guys.

Thanks in advance.

:bust_in_silhouette: Reply From: jgodfrey

While I’ve never used it, the docs seem pretty straight-forward. Really, it just provides a way for you to define a set of nodes that a given RayCast2D instance should not interact with.

So, for example, if your scene has a tree in it that you want your raycast to ignore, you can simply add the tree to the ignore list. So, assuming $RayCast2D and $Tree are valid node references in your scene, something like this:


With that, the raycast will not detect collisions with the tree. And, obviously, you can add as many objects as you want to the exception collection.

You can do similar things with collision layers or type masks. The add_exception() method is just another option.