Check if object faces camera

I want to trigger events based on the rotation of a mesh in 3d space. Currently I’m translating input from a gyro to the mesh (which works incredibly well - thx quaternions!).

My previous approach was to compare the vectors (gyro input) with fixed values. This works ok but depending on movement, there are multiple ways to rotate the 3d mesh to each position. So sometimes the events would not trigger.

New approach: Place quad on the mesh, whenever the normals face the camera -> trigger. Stuck here.

How can I checking if a quad is facing the camera (± tolerance)?

this is usually done with the dot product. if you compare two normalized vectors, the dot product is 0 when they are perpendicular (maximum direction difference), 1 if they face in exactly the same direction, -1 if they point in opposite directions.

so you only need a forward vector and compare it with a fixed vector using the dot product.

1 Like

very helpful, thank you!

I’m using Arrow to visualize the trigger vector (interesting point person should look at). Decomposing the incoming Translation, feeding the RotateXYZ into Normalize -> * (3d dot). The fixed vector points towards the camera -> Decompose RotateXYZ -> Normalize -> * (3d dot).

Good reliable values, off to a great start.

The only problem is, I can rotate the 3d mesh around itself, so while the vector still faces me, this impacts the value I’m getting out of the dot product. I only really care about the direction the vector is pointing, not the rotation. Can you point me into the right direction?

the RotationXYZ are euler angles, it is not a direction vector. you can just use ApplyTransform on a (0, 0, 1) vector to get the transformed forward vector.

1 Like

This works perfectly - Thank you! This approach feels much more elegant now.

I’ve attached the solution that’s working for me in case anybody stumbles upon this.


1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.