- Home /
Question by
popcornistleckerokay · May 22, 2020 at 08:10 PM ·
cameratransform.positionaxisrotation axis
How to get the Z - Axis of the Cam
Hey,
i have this line in my code:
transform.rotation = Quaternion.Slerp(transform.rotation,cam.transform.rotation, 0.1f);
i need only the z axis of my code so logically something like this cam.transform.rotation.z. sadly this doesnt work. any suggestions on how to do it?
Comment
Answer by YoannHx · May 22, 2020 at 09:32 PM
cameraZRotation = Quaternion.Euler(0, 0, cam.transform.rotation.eulerAngles.z);
I'm sure there's a cleaner way to do this without switching back to Euler angles but my math is rusty and well... Whatever works until performance is not an issue!
(Note: I just used that to restrict camera rotation around Y in a small practice project, see here with source code linked)
Answer by UXT · May 22, 2020 at 10:26 PM
Try this float CameraZRotation = CameraTransform.rotation.z