Essentially, I have the following basic vector calculation:
var CamTrans = Camera.main.transform;
var endPos = CamTrans.position + (CamTrans.forward.normalized * renderDistanceInBlocks);
vector3 RenderLine = endPos - camTrans
I’m doing a procedural generation hobby-project, and I want to optimize my engine even further. I am trying to render objects from a grid of candidates based mainly on their proximity to the RenderLine. I googled and found some beastly math, but does Unity have a convenient way to calculate the distance of a point from a line so I can simply:
-
Get the above vector
-
Get the distance of every object from that vector (the step I am asking about)
-
draw only objects within x distance of this vector
-
draw the rest.
I can easily get three and four down, but two is tricky.
Thanks for reading this far, and if the answer is already here somewhere (I searched previous questions as well), please copy-past the link for an easy accepted answer.