I am making a game in curved space in Unity and I am trying to figure out the best way to handle raycasting. For my purposes the
Ray struct doesn't carry enough information so I started by writing a custom ray struct. I suppose next I need to write a custom collider class but I'm not sure whether I should inherit from Unity's
Collider class. The
Collider class has a
Raycast function that I could overload, but the function signature takes normal
Rays. It would be cool if I could just interface with the normal Unity physics raycasting system, but it looks like that won't work because it's all built around passing around
So what I'm thinking is I'll write a custom static physics class which will have a raycast function which will loop over all the custom colliders in the scene and find which one my custom ray hits first. I suppose I will also have to write my own version of the
RaycastHit class since the existing
RaycastHit has a field that carries
The alternative is my custom collider could inherit from the Unity
Collider and add a new version of
Raycast that takes my custom rays. Then I could use the existing
RaycastHit class, but I would still have to write my own physics class.
So my first question is how I should structure all this. I've given it some thought but I'm looking for input from someone with a deeper understanding of Unity. Next, I have one particular object that I'm interested in raycasting that will have a large mesh and I need to know which triangle is hit by the raycast. I suppose I should make a custom mesh collider class that inherits from
So I'm just looking for insight into the cleanest way to organize all this. Thank you for any advice you can offer!