I am trying to get the camera to rotate towards a location and position. Which works at the moment, but once it is done and re enables the mouse look script or bool in the script the mouse look overrides the rotation and sets it back to the original rotation it had when the rotation started.
if (lockedOn)
{
// Get the direction to the target
Vector3 direction = target.transform.position - transform.position;
// Calculate the rotation to face the target
Quaternion rotationToTarget = Quaternion.LookRotation(direction, Vector3.up);
// Rotate towards the target over time
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationToTarget, rotationSpeed * Time.deltaTime);
if (currentFOV >= closeFOV)
{
curRotation = transform.rotation;
currentFOV -= fovSpeed * Time.deltaTime;
camera.fieldOfView = currentFOV;
}
}
if (!lockedOn)
{
if (currentFOV <= startFOV)
{
currentFOV += fovSpeed * Time.deltaTime;
camera.fieldOfView = currentFOV;
transform.rotation = curRotation;
if (camera.fieldOfView >= startFOV)
{
target = null;
transform.localRotation = curRotation;
mouseLook.lockControls = false;
}
}
}
if (removeFromCharacter)
{
// Distance moved equals elapsed time times speed..
float distCovered = (Time.time - startTime) * cameraMoveSpeed;
// Fraction of journey completed equals current distance divided by total distance.
float fractionOfJourney = distCovered / journeyLength;
// Set our position as a fraction of the distance between the markers.
transform.position = Vector3.Lerp(origCameraLocation.transform.position, newCameraLocation.position, fractionOfJourney);
}
and the mouse look script
if(!lockControls)
{
// Get mouse input
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
// Rotate the player's body based on horizontal mouse movement
playerBody.Rotate(Vector3.up * mouseX * sensitivity);
// Calculate the new vertical rotation
rotationX -= mouseY * sensitivity;
rotationX = Mathf.Clamp(rotationX, -verticalLookLimit, verticalLookLimit);
// Apply the rotations to the camera and player body
transform.localRotation = Quaternion.Euler(rotationX, 0f, 0f);
}