Anthony,

I want to save the initial camera position for reset on each level start.
I move the cam to the given position and the position vector seems correct directly after moving.
But short after this the camera position z value changes. I did not understand why. Now The camera position is not correct.

    private void Awake()
    {
        InitialPosition = cameraPerspective.transform.localPosition;
        InitialRotation = cameraPerspective.transform.localRotation;
    }

    private void MoveToInitial()
    {
        Debug.Log("move to initial");
        Debug.Log("current position: " + cameraPerspective.transform.localPosition);
        Debug.Log("initial position: " + InitialPosition);
        cameraPerspective.MoveCameraToInstant(InitialPosition, InitialRotation);
        Debug.Log("position after move: " + cameraPerspective.transform.localPosition);
    }

Logs

move to initial
current position: (-4.49, 9.64, -8.34)
initial position: (-4.49, 9.64, -8.34)
position after move: (-4.49, 9.64, -8.34)

But the camera changes z-value to -7.49 instead -8.34 after that. How can I prevent this?

Thanks

    Dennis Hi!

    MoveCameraToInstant() needs a frame to update on the latest version, since all movements are done in the Update() calls.

    But if I understand right, the camera jumps anyway on z, so that might be an issue. I will investigate that and keep you posted!

      Dennis There is an approximation caused by the recalculation of all parameters based on raycasts.

      If you want to avoid all this, add this method in your CameraPerspective.cs class:

             public void ApplyPositionRotation(Vector3 p, Quaternion r)
             {
                  finalOffset = CalculateOffset(p, r);
                  finalDistance = CalculateDistance(p, r);
                  finalRotation = r;
                  finalPosition = p;
      
                  ApplyToCamera();
              }

      Then call ApplyPositionRotation() instead of MoveCameraToInstant()

      😉

        Thank you.
        I think there is another problem in my code. Nothing changes with your function.

        I will skip this camera moving feature

          Dennis let me know if you need my help to figure it out!

            Write a Reply...