- Home /
How to rotate on one axis while keeping the other axes open to be rotated by other scripts?
I'm working on a wallrunning script using the standard rigidbody controller (I have to use this one, I can't use the Character Controller), and I'm trying to get the camera to rotate ~30 degrees on the Z axis when wallrunning, like a lean effect. However, most methods I've tried have constrained the X and Y values of my camera to either 0, or the value they were before wallrunning started. I need to be able to move every axis with other scripts, just have 30 added or subtracted from the Z axis.
One big problem is that the charactercontroller script rotates the camera back every frame, so I can't just set the rotation at the start of the function, it has to be in the Update loop for the wallrun.
Here's a list of the things I've tried:
transform.Rotate (0, 0, 30);
cam.transform.rotation = Quaternion.AngleAxis (30, cam.transform.forward);
cam.transform.rotation = Quaternion.Euler(new Vector3(0, 0, -30));
Answer by A_Lego · Nov 10, 2018 at 08:11 PM
Vector3 camEuler = cam.transform.rotation.eulerAngles;
camEuler.z = 30;
cam.transform.rotation = Quaternion.Euler(camEuler);
or this too
cam.transform.rotation = Quaternion.Euler(cam.transform.rotation.eulerAngles.x,cam.transform.rotation.eulerAngles.y,30);
Your answer
Follow this Question
Related Questions
Auto leveling help 0 Answers
Problem using Quaternion.AngleAxis around transform.up 1 Answer
Why is this rotation acting odd? 0 Answers
Use a single rotation axis of a freely rotating object 1 Answer
Quaternions acting up 1 Answer