FinalPosition is only a getter (without making changes to orig code), and I attempted the second suggestion of disabling scripts, changing camera transform position and then re-enabling them--didn't seem to work.

What would it take to code a method such as RepositionCamera() that would effectively move the position of the actual camera (not its focal point) to a specified Vector3? Thanks Anthony!

    5 days later

    heiser Sorry for the late reply.

    Can you try adding this to your CameraBase.cs?

        /// <summary>
        /// Moves the Camera transform position to a new position, in 1 frame
        /// </summary>
        /// <param name="targetCamPos"></param>
        public void RelocateCameraInstant(Vector3 targetCamPos)
        {
            finalPosition = targetCamPos;
            finalOffset = CalculateOffset(finalPosition, finalRotation);
            finalDistance = CalculateDistance(finalPosition, finalRotation);
           
            ApplyToCamera();
        }

    Or if you want a more complex one that clamps the camera in boundaries:

        /// <summary>
        /// Moves the Camera transform position to a new position, in 1 frame
        /// </summary>
        /// <param name="targetCamPos"></param>
        public void RelocateCameraInstant(Vector3 targetCamPos)
        {
            finalPosition = targetCamPos;
            finalOffset = CalculateOffset(finalPosition, finalRotation);
            finalOffset = ClampInCameraBoundaries(finalOffset);
            finalDistance = CalculateDistance(finalPosition, finalRotation);
            finalPosition = CalculatePosition(finalOffset, finalRotation, finalDistance);
    
            ApplyToCamera();
        }

      Hi Anthony,

      Those worked great, thanks!

      I just needed to make one little adjustment to it, and been having some trouble figuring out how to implement it within the TouchCameraPro libs....

      Suppose the perspective camera is in Rotate Around mode, looking down at a 45 degree angle. When I execute RelocateCameraInstant and put it into Rotate Head mode, it repositions the camera to the focal point, which is great. But the angle after the camera was relocated is still at the 45 degrees (which makes sense), but I need it to now be looking in the same direction but parallel to the floor, not at the floor at 45 degrees. I attempted several mods to adapt this behavior into the method:

         `public void RelocateCameraInstant(Vector3 targetCamPos, Quaternion targetRotation)
          {
              finalRotation = targetRotation;
      
              //Vector3 euler = FinalRotation.eulerAngles;
              //Vector3 yawOnly = new Vector3(0, euler.y, 0);
              //finalRotation = Quaternion.Euler(yawOnly);
      
              finalPosition = targetCamPos;
              finalOffset = CalculateOffset(finalPosition, finalRotation);
              finalDistance = CalculateDistance(finalPosition, finalRotation);
      
              //finalRotation = targetRotation;
      
              ApplyToCamera();
          }`

      The idea was to pass a Quaternion that contained the same direction as the current rotation, only parallel to the ground. But this has not worked in the few different ways that I tried. Is there a problem with the code, or do you think there is a problem with the Quaternion I am passing in? If the former, please let me know the adjustments I should make. If the latter, how would I then derive the quaternion of the existing rotation but be parallel to the ground and not looking at the ground?

      Thank you!

        Hi!
        Which camera mode are you using?
        The RotateHead mode is only to be used with the experimental "free camera" mode, all other modes are meant to look at the floor, so having the camera parallel won't work. Have you checked the Free Camera demos?

          When I am in RotateHead mode, I am able to use touch controls to bring the camera line of site parallel with the ground, so it should work. Perhaps I am not explaining it well, I will attach an image that will helpfully better explain.

          Visual Explanation

            6 days later

            heiser sorry for the late reply, there is a lot going on.
            I understanf what you want to so now. Just leave the camera rotation as is. While moving the position.

            Have you tried assigning the finalRotation variable inside RelocateCamera?

            Just before applytocamera()

            Add finalRotation=transform.rotation

            If doesnt work I can try on my side to make it work, but again it’s not something I support since it’s not meant to look out of the floor.

            Maybe what you should do is using Cinemachine with the virtual cameras. To switch between touch camera’s top down view and your object FPS view.

              Hi Anthony,

              Yes, I tried that but unfortunately it did not work. Please read the comments in the code below where I added some notes. Thanks!!

                  `public void RelocateCameraInstant(Vector3 targetCamPos, Quaternion targetRotation)
                  {
                      finalPosition = targetCamPos;
                      finalOffset = CalculateOffset(finalPosition, finalRotation);
                      finalDistance = CalculateDistance(finalPosition, finalRotation);
              
                      // The camera ends up pointing in the correct direction, we just want to modify the pitch.
                      // So instead of looking down at the ground at the same angle the camera had before the call
                      // to RelocateCameraInstant, we want the view to be straight out; IOW, not pitched up at 
                      // the sky, not pitched down at the ground, but straight out.
                      //
                      // To make this universal, I modified the function to accept a targetRotation, so the
                      // function not only relocated the camera to a new position, but also adjusts its rotation
                      // to the correct value.
                      //
                      // I have tried to set the final finalRotation to many different values before ApplyToCamera, including the
                      // passed-in target rotation, but it doesn't seem to alter anything. Perhaps the value I 
                      // set it to is overriden by some calc in the tool code? I also tried setting finalRotation at the very beginning
                      // of the function.
              
                      //finalRotation = targetRotation; 
                      finalRotation = transform.rotation;
              
                      ApplyToCamera();
                  }

              `

                8 days later

                Hi!
                I don't think it's the right approach as TouchCamera is not meant to be a POV camera, there is indeed calculation in the Update loop that takes control of the position/rotation depending on the floor.

                The right approach for what you want to do is simply to use virtual cameras. Cinemachine is really meant for it. I went ahead and made a demo scene for you using Cinemachine, that smoothly switches between the top down view camera and POV camera inside moving cubes on the floor. I also updated the manual to explain how it works.
                I pushed the update on the store it should be available in 2 days top.

                Hope that will work for you!
                Anthony

                  5 days later

                  Great, thanks so much for doing this! I'll check it out

                    8 days later

                    Hi Anthony

                    I upgraded from TouchCameraPro 3.0.6 to 3.1.0 and some things have stopped working. I can zoom in and out (using the mouse wheel), and switch between persp and ortho just fine, but I cannot move/translate the space, the camera is fixed and no longer moves as if those touches aren't registering. I also deleted the TouchCamera prefabs and reimported to be sure. I will continue to investigate, but does this sound like an issue you've come across before?

                    Thanks!
                    Chris

                      To add on to my last post...I can see the coordinates update under the Fingers section of the TouchCameraInputs section, so I know its detecting the touch movement...just doesn't seem to make its way to the camera. I also made sure to delete the older files before importing the package. Thanks

                        heiser sorry to hear about this issue. Can you check that the event system in your scene does not have any error displayed?
                        Can you also open any of the demo scene to check if you encounter the same problem?

                        We could schedule a quick debug call with team viewer if you want to me to have a closer look, let me know.

                          I reverted back to 3.0.6, but I kept the updated project, so if I get some extra time I will dive back in and look at the event system etc.

                          The good news is that I followed your demo and successfully applied Cinemachine to my app that is on 3.0.6 and it is working great. Thanks!

                            Write a Reply...