Hi,
I’m creating a space game, and I’m trying to use quaternions to allow the player to orbit the camera around the ship using the mouse while the “Freelook” key is held down, similar to holding down alt and looking around in Arma/Dayz. I have a “CameraDolly” which smoothly matches the camera’s rotation to that of the SpaceShip. The child of the Dolly is the “CameraAxis” which manages how far from the CameraDolly the player has rotated the camera. This is just so I can work using localRotation instead of rotation. Therefore, to look around, the player will be modifying the localRotation of the CameraAxis.
FreecamYTarget is the new TargetYvalue and the FreecamTarget is the new target quaternion. The localRotation of the cameraAxis will slerp from its current value to the target.
FreeCamYTarget = _cameraaxis.transform.localRotation.y+_playercontrols.Ship.Look.ReadValue<Vector2>().x;
FreecamTarget = new Quaternion(_cameraaxis.transform.localRotation.x, FreeCamYTarget, _cameraaxis.transform.localRotation.z, 1);
_cameraaxis.transform.localRotation = Quaternion.Slerp(_cameraaxis.transform.localRotation, FreecamTarget, Time.deltaTime * FreeLookSensitivity);
The CameraAxis localRotation constantly twitches between its default position and some random yvalue when it should just be orbiting around the ship as per the mouse input. I’ve attached a video:
Pretty sure the issue is down to my poor understanding of Quaternions, but I’d appreciate your advice since I’ve been scratching my head over this for days. Thanks