I am currently attempting to lock a non rigid body transform rotation around on an axis. It is parented to a gameobject that is rotating in 3D space. I want the Original transform to have the same rotation as the parent's but I want it to be locked on a certain certain axis. For the sake of clarifying my question I will provide some code and an example.
Example: There is a 3D model with a plane attached to the left upper arm subsegment(see hierarchy) whose initial normal is aligned with the global x-axis <1,0,0> or the initial right vector of the subsegment. In the context of this post, what I would like is to be able to align the normal of the plane with the subsegment's right vector but keep the plane's up axis locked.
For instance, I do not want to the yaw component of the transform to change. Trying the following code does not result in the intended effect.
Vector3 eulerRepresentation = parent.transform.rotation.eulerAngles; eulerRepresentation.y = 0; Quaternion fromEuler = Quaternion.Euler(eulerRepresentation); transform.rotation = fromEuler;
This is very likely because of the duality of a rotation of Euler angles. An example is (180,0,180) is the same as (0,180,0)
When inspecting the euler values, it is exactly like I suspected. There doesn't seem to be correlation with the object's yaw and the object's euler.y value.
How would I go about locking either Yaw/pitch/roll?