I’m having trouble finding a solution for a problem.
What I’m looking for is the position within an area. My area is a triangles, so I’ve got 3 positions. I also have a 4th position and a direction. I want to find the position withing the area based on the 4th position and the direction. Unfortunately I cannot use a raycast, which would make it rather easy. I have to calculate it, but I can’t figure out the right solution for it.
Does anyone know something that would help me?
I attached an image for better understanding what I’m looking for.
Excactly, the line is crossing the triangle somewhere, it’s not always the same position, and I need to find the position where the line “hits” the triangle. It’s in 3D. That is why I need to use the direction to calulate the positions, I guess.
I tried something where I calculate the point on each of the 3 lines and then I took the 3 positions on the lines and divided them by 3. Didn’t work exactly as I need it.
What this code does is taking a line (with start and end position) and calulates the position in the line if there would be a straight line hitting the first line at a 90° angle.
I can’t use the collider of the mesh in this case. I use it to update the position of some objects when terraforming the terrain. If I assign the mesh as meshcollider the game freezes for a moment, so I need to calculate it.
Also I’m not using a plane. But good to know that there is a Plane.Raycast. Might come in handy at some point.
Oh ok, didn’t know that. If you’re not using a plane than the other solution works pretty well. I use the triangles from a mesh after I adjustes the vertices and it does the job for me.