Hi,

I'm having difficulty adapting your FreeCamera script. Currently the camera relies on clicking the mesh of the scene to translate the camera, however, I am trying to change the script so that it simply moves the camera along it's X/Y axis by getting the delta from the screenspace for finger/pointer movement. I can easily enough move the camera to the new target position but it's unclear what needs to be done about distance and offset?

`
finalOffset = newWorldPointCameraCenterClamped;
finalDistance = CalculateClampedDistance(finalPosition, newWorldPointCameraCenter, minMaxDistance);
//finalPosition = CalculatePosition(newWorldPointCameraCenterClamped, finalRotation, finalDistance);

                var scaleFactor = -0.5f;

                var x = Input.GetAxis("Mouse X") * scaleFactor ;
                var y = Input.GetAxis("Mouse Y") * scaleFactor ;
                
                var move = transform.right.normalized * x + transform.up.normalized * y;
                var target = transform.position + move;

                finalPosition = target;

                CalculateInertia();

`

Could you please advise?

Many thanks

    4 days later

    CaptainBaxter finalDistance

    CaptainBaxter hi!
    In this case, you need to calculate finalRotation (if changing), and finalPosition before calling ApplyToCamera() basically.

    The finalOffset is basically the projection of the camera center on the object collider, from the world position (0 0 0) you can skip that if you're not using colliders.

    The finalDistance is the distance between the projection of the camera center on the collider and the camera position. So that when you zoom in/out this value gets incremented and the camera position changes.

    Your code looks good to me if you just want to handle the camera position X/Y, you just need to call ApplyToCamera() after, but you will have issues if you are still using the other features too (zoom, follow etc)

      6 days later

      Hi Anthony,

      Thank you for your response. I basically want to update the script so that the pan movement in aligned to the camera X/Y rather than aligning it to the surface you are clicking on. I would like to keep all of the other functionality so this is the only part of the script I have changed. I am still getting some strange behaviour with the zoom, it will fly off to extreme distances and the rotation will sometimes move the camera to the wrong location.

      I think I understand your logic correctly, there's quite a lot of abstraction so it's hard to follow, but I believe you are using the offset value as the location of the pivot point for the orbit controls then the distance is the distance from that point to the camera? You then calculate the angle from that pivot point?

      Many thanks

        CaptainBaxter yes that's basically it.
        if you pan along the camera X/Y the finalDistance has to be recalculated too yes, there are some methods like CalculateDistance(pos, rot) that could help you

          Write a Reply...