How to make raycast avoid a object

Hello, is there a way for raycast to not hit the player but go through? Thanks. PS: i found a code in aswers but i think is more complicated than i need since the only object i want to avoid is the player tnx.

You can do a standard raycast and if it hits the player entity, do another raycast using the intersection point (moved slightly forward) as the new starting point for the ray.

The other way is to use physics filters but that would mean writing your own raycast function that takes the filters into account.

Ok @yaustar got it…will need some time to study…again…lol never ending learning here lol

I know this is a somewhat old post, but in case someone else ends up here, the technique we used was to load references to the matched entities into a buffer and apply some code to filter the buffer.

So for example, in one case we wanted the object farthest from the camera so we pulled out the refs, sorted them by the appropriate axis in the buffer and then popped the last reference in the buffer. We used the reverse of the sort to get the closest, etc.