I have a camera that is following an aeroplane object, that can rotate left/right. I want to prevent the camera from rotating on this axis (z-axis).
this.transform.rotation = Cube.transform.rotation;
This obviously rotates the camera in all directions the plane can move in.
I've been trying various things with zAxis etc, only rotating on x and y...
this.transform.Rotate(Cube.transform.rotation.xAngle, 0, 0, Space.Self);
CodePudding user response:
I believe you wanna try set the same rotation, and omit the Z axis, as such
Vector3 rotation = Cube.transform.rotation;
rotation.z = 0;
this.transform.eulerAngles = rotation;
This should set the rotation of the camera to be the same as your cube, without the Z axis.
CodePudding user response:
Try to put a Configurable Joint and block the directions that you don't want to use