Force in direction of triangle's UV forward vector?

Ok, so read carefully: I’ve been wanting to make a mesh force other rigidbodies in the direction of it’s triangle UV. So, for example, you have one mesh that has a series of planes with textures that resemble conveyor belts. You would be able to aim the force that the conveyor belt produces by mapping the texture in your modeler. My question is how do you find the triangle’s uv transform.forward vector that the rigidbody collided with?

I know this is a bit confusing, but the idea could help me out enormously.

There’s a technical obstacle with your request. UVS are bi-dimensional, so there actually no ‘forward’, for them, but only normalized x and y, relative to the 0-0 corner and 1-1 corner coordinates of the texture.

What you need to do is certainly create a meta data structure, where you assign one ‘forward’ to each interested triangle, or set of triangles, based on a rule that you must implement.

Triangles can be accessed through the mesh component of any model.

So I think the easiest way to find the force direction in terms of the triangle is to actually raycast to get the triangleIndex when you hit the collider - that only works when the thing you hit is a MeshCollider though - and they are rather slow and liable to backface culling which could cause you problems. Otherwise you could simulate a ray cast by taking a line from your object in the direction of -transform.up and test it against all of the triangles in your mesh.

Once you have the triangle index then you are going to want to decide on the vector you want in terms of UV. Say from (0,0) to (1,0) for a horizontal then you are going to need the three UV coordinates of the points of the hit triangle and decide the direction which changes U but not V (I’m struggling to be sure that this is always possible). I’m guessing you just take point 1’s V and then solve the equation of the opposite line (point 2 to point3) for that value of V which now gives you a second point. The force direction would be the line connecting point 1 and the found point on the line from point 2 to point 3.

With a triangle index it is trivial to find the UV of each of the points - use the triangles array, multiply your triangleIndex by 3 and select the UVs for the three indicies found there.