• Touch Camera
  • Follow Object not Working Properly(?) and Using Keyboard to Move the Camera

Hi again!

I noticed on your manual that you have Following Object feature, and it works perfectly on its own! Although when I tried to integrate it with your Home Designer asset, the camera starts to not work properly for its furniture after I trigger this event
CameraEvents.OnRequestObjectFollow?.Invoke(gameObject, focusOnFollow);
Am I doing something wrong? Or maybe you already have it in your demo scene, but it's just me that missed it haha? 😅

For another question, I tried to add a simple function to move the camera with a button input based on your CameraPerspective.cs script. But it seems that you need to click/tap the screen in order to calculate the movement. Do you have solutions in mind to approach this one?

Sorry for the double question! Not sure if I should separate it into different discussions or not haha 😅

    gabriabel Hi !

    1. if I understand right, you try to focus on the object after you dropped it right ? What I see from the video is that the object disappears and the camera follows it ?
      if you search in the code you should find example of the camera focus, so if you copied that, I don't think you did anything wrong, I just would like to know why your object disappears ? Feel free to send me an example projet if you will 😉

    2. The camera only moves using inputs in my demo, or by selecting an object, but you can easily add a function to move it with input keys or ui buttons. You just have to add a function to provide a new position (offset) and distance to the camera. For example add this function and call it during an Update() loop :

            public void MoveCameraTo(Vector3 targetOffset, float targetDistance, float lerp=.1f)
            {
                finalOffset = Vector3.Lerp(finalOffset, targetOffset, lerp);
                finalDistance = Mathf.Lerp(finalDistance, targetDistance, lerp);
                finalPosition = CalculateNewPosition(finalOffset, finalRotation, finalDistance);
                ApplyToCamera();
            }

    Or remove the Lerp, if you want to set the position straight away without animation, this is just an example.

      Anthony Hi, thanks for the reply!

      1. Sorry, it seems that my video is not clear enough 😅. The object doesn't disappear from the scene, it's just the camera somehow not "following" the object. Assuming that "focus" and "following" is different function altogether, the problem is not the "focus" on the object but the "following" on the object. In this video, you can see that the "focus" function is okay. But when I trigger the "following" function, the camera started to shake a lot.
        Is it because there is some line of codes that overlaps with each other? If you feel like this is not enough information, I can send you an example project for this case

      2. Ah I see! Before, I only tried to change the finalPosition's value and not recalculate the whole thing. I didn't reconsider the new center of the camera at all. That's why the camera gets "stuck" to its initial position after I changed its position. Just tried it again with something like this and it works:

                    if (Input.GetKey(KeyCode.LeftArrow))
                    {
                        // temp line for testing only
                        finalPosition = new Vector3(finalPosition.x - 0.1f, finalPosition.y, finalPosition.z);
        
                        Vector3 newWorldPointCameraCenter = CalculateNewCenter(finalPosition, finalRotation);
                        finalOffset = newWorldPointCameraCenter;
        
                        finalPosition = CalculateNewPosition(finalOffset, finalRotation, finalDistance);
                    }

        From here on I can adjust it based on what I needed. Thanks for the insight! 😁

        5 days later

        gabriabel How is it going so far?
        Yes please don't hesitate to send me an example project so I can investigate the issue if you still have one. Please note that I will note be able to check it before the 5th of December.

          Anthony
          Hi!

          Turns out, it was because I already edited a lot of your base scripts, and some of those changes made that error appears.
          So I decided to try another approach for this one as a workaround, which doesn't require the game to follow the object.

          I wanted to give you a sample project based on my current one but I cannot recreate it anymore haha 😅. And because this error is a special case, I don't think you have to worry about it anymore. Thanks again!

          Write a Reply...