i want a raycast to only collide with an object, and viceversa

so i have a sphere where raycast from the camera will collide, I only want that raycast to collide with that sphere, not with anything that could get in the way (say a bullet or something). also I want that sphere to not let any other raycast.

p.s. please note that I don’t ask you to write code for me, simply to explain me how to make it work, that way I will understand it if any tweeks are needed in the future.

thank you for all your help.

1 Answer

1

Instead of raycasting by using Physics.Raycast, you instead call raycast on the collider itself. This only performs the raycast against that specific collider.

BTW Thanks for not asking for code! I didn’t feel like your question implied that, so no worries.

thanks, this really helps, i asked for code this time because last time I was expecting a link or something but someone showed up with a huge code. really appreciate it and it did the trick, but it was not very helpful since I did not understand it