I’m trying to detect when two objects are mirrored. I’m seen this question asked in the past and the best and simplest answer is checking if the dot product of the forward vectors is -1. Something like:
If I get the transform.forward for those, they’re coming out the same: Both 0, 0, 1. Shouldn’t it be different, because if you worked out which way they were actually facing, they’d be the opposite to each other?
Then of course when I do the dot product, it does 1 * 1 and gets 1, not zero. Any hints would be very appreciated.
I’ve actually managed to solve my own problem, and for anyone in the future with the same issue I’ll explain it here, because it took me ages to work out.
Any 3D rotation will have one axis which just rotates the object, but doesn’t change the direction it’s actually facing. Imagine a wheel spinning on a car - it’s rotating but still facing the same way.
Now, normally in Unity this is a Z axis - hence my forward vectors were always coming out the same when I rotated Z. Unfortunately my objects were changing they way they faced when I rotated the Z, because I’d imported the models from Blender, and in Blender the Z axis is up instead of Y, meaning everything had a 90 degree rotation.
I decided to go into Blender and rotate my objects -90 degrees on the X axis, apply it, and then rotate 90 degrees and save. This then matches the objects visually between Blender and Unity but the 90-degree rotation that messed everything up doesn’t have to be applied, and the problem is fixed.
I imagine the problem could also be fixed by multiplying the forward vector by your actual forward vector.
I figured out this this
var value = Mathf.Abs(obj1.transform.rotation.y - obj2.transform.rotation.y);
this ranges from 0 to 1 if you rotate any of two objects
if both objects are completely oposite to each other value will be 1 and in the case, object 1 and 2 are parallel value will be 0