I been working on my third person camera and am running into issues with rotations.
I want my camera to rotate around a pivot. The rotations can be up and down (pitch), left and right (yaw), or tilting left and right (roll). I also want my player to rotate the same as the yaw rotation.
So, I did something like this…
void PitchRotation()
{
float pitchAmount = Input.GetAxis("Mouse Y") * 5f;
pivot.Rotate(pitchAmount, 0, 0);
}
void RollRotation()
{
//Doesnt work since localEulerAngles.z seems to be giving eulerAngles in world space?
//pivot.rotation = Quaternion.Euler(pivot.localEulerAngles.x, pivot.localEulerAngles.y, targetZRotation.localEulerAngles.z);
//Works, but Pitch then does not work at all.
//pivot.rotation = Quaternion.FromToRotation(pivot.up, targetZRotation.up) * pivot.rotation;
}
void YawRotation()
{
float turnAmount = Input.GetAxis("Mouse X") * 10f;
pivot.Rotate(player.up, turnAmount, Space.World);
}
//Somewhere on the player
transform.localRotation = Quaternion.Euler(transform.localEulerAngles.x, playerCamera.pivot.localEulerAngles.y, transform.localEulerAngles.z);
//Does not work if the player up axis is not the world up axis (he is rotated such as by walking on walls). Also, although I am using localRotation, regular rotation gives the same results..
The issues I am having are from when the player is rotated weirdly by walking on walls or something. The player trying to rotate to follow the cameras Yaw rotation will not work when the player is rotated on the z axis, and the Cameras pivot RollRotation will also not work.
The localEuler values werent what I thought they might act like, and by trying something like FromToRotation, it works, but then locks my pitch rotation…
I was able to fix the Roll problem by just using another transform to be the axis, and then having the pivot by a child of that, however, I still have the issue of my player not rotating properly.
Any help is appreciated =)