- Home /
How can I change Z rotation of a FPS player ?
Well I am challenged by making my player tilt his body, so I should change the Z rotation(when I press Q or E), but have some issues whit it because my camera moves really questionable while I am pressing Q or E and moving the mouse. Here is some part of the code: if (Input.GetKey(KeyCode.Q)) { playerController.transform.rotation = Quaternion.Euler(0, 0, 20 Time.deltaTime * 10);
Quaternion t = playerController.transform.rotation * Quaternion.Euler(0, 0, 20 * Time.deltaTime * 10);
if (t.eulerAngles.z > 20)
{
t = Quaternion.Euler(t.eulerAngles.x, t.eulerAngles.y, 20);
}
playerController.transform.rotation = t;
}
Answer by Zentiu · Mar 20, 2020 at 11:25 PM
The Z axis is depth so if you rotate that it will move from side to side.
What i Always do if i want to rotate something is use eulerangles. This is how i would use it:
vector3 rotation = transform.eulerangles;
rotation += new nector3(0f, 0f, //whatever you wish to set the Z axis. this will be added);
transform.eulerangles = rotation;
if i have a variable for the Z axis then i can use whatever i want like 'Q' or 'E' or mouseInput to set how fast or how far i want the Z axis to be. If the value is below 0 it will work as well. I don't deal with quaternions since they are pretty hard to understand for me.
I hope this answer is helpful. if not then let me know.
@Zentiu For me either, this quaternions are just like a black spot. Well actually I have managed to fix it somehow, but thaks for the answer <3.
Your answer
Follow this Question
Related Questions
Mouse Aiming + Fixed Camera + Independent Keyboard Movement 3 Answers
Mouse movement object in a straight line 2 Answers
Move relative to screen 0 Answers
How do I add a camera bounce effect every time the player lands? 0 Answers
Camera movement help 1 Answer