How to get JUST the y rotation of an object?

I’m making a 3rd person game with the controls set up so that:

If the player holds down forward on the left stick (i.e. runs forward) and rotates the camera left/right, he’ll run the way the camera’s facing.

HOWEVER, my problem is that he is also running the way the camera is facing, rotated around the x/z axis too, so he’s turning and facing the sky rather than just running on the x,z plane.

I’m not familiar with matricies, quaternions, or eulr’s, so is there a way I can make my character ONLY rotate around the y axis (so that he only runs on the x,z plane), not all 3?

the code I’m using is: “transform.rotation = cameraParent.transform.rotation;”, I’m just not sure how to split it up so that it only changes the rotation around the y axis since transform.rotation.y only returns a value and can not be set by calling that

You could just get the euler y angle of the camera:

float yRotation = cameraParent.transform.eulerAngles.y;

Then assign it to the transform:

transform.eulerAngles = new Vector3( transform.eulerAngles.x, yRotation, transform.eulerAngles.z );

You only wish to access

cameraParent.transform.rotation.y

but you can’t modify that property by itself, so you need to store it in a temporary variable and then apply the rotation like this:

Vector3 newRotation = transform.rotation;
newRotation.y = cameraParent.transform.rotation.y;
transform.rotation = newRotation;

Should be something like:

transform.rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, newRotationValue, transform.rotation.eulerAngles.z);