'How to add an orbit rotation on this script : smooth zoom and pan (work very well)

i want to use a script that work fine but need something more. This script was publish by Vpellen. So it works fine, but I want to do something more, because finally we can't turn around the Y axis, and there are no rotation at all finally(i suppose; X axis isn't necessary because there are already the zoom)like an orbit camera. I have tried to mix with other script but the camera orbit turn around the position on the floor and I think it should turn around with a new position that it's egal to the new height max of the zoom, and always look At on the floor(the orbit point on the floor).

I'm not sure if I am clear(english isn't my natal language too). What's should I change to add this function.

I make a shema, hopefully it help to understand my problem Click Here to see the shema in big click to see my shema to understand exatcly what I want

Thank you if you can help me, I try to fix that since a moment.

The script:

using UnityEngine;

public class RTSCamera : MonoBehaviour
{
    public float zoomSpeed = 100f;
    public float zoomTime = 0.1f;

    public float maxHeight = 100f;
    public float minHeight = 20f;

    public float focusHeight = 10f;
    public float focusDistance = 20f;

    public int panBorder = 25;
    public float dragPanSpeed = 25f;
    public float edgePanSpeed = 25f;
    public float keyPanSpeed = 25f;

    private float zoomVelocity = 0f;
    private float targetHeight;

    void Start()
    {
        // Start zoomed out
        targetHeight = maxHeight;
    }

    void Update()
    {
        var newPosition = transform.position;

        // First, calculate the height we want the camera to be at
        targetHeight += Input.GetAxis("Mouse ScrollWheel") * zoomSpeed * -1f;
        targetHeight = Mathf.Clamp(targetHeight, minHeight, maxHeight);

        // Then, interpolate smoothly towards that height
        newPosition.y = Mathf.SmoothDamp(transform.position.y, targetHeight, ref zoomVelocity, zoomTime);

        // Always pan the camera using the keys
        var pan = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * keyPanSpeed * Time.deltaTime;

        // Optionally pan the camera by either dragging with middle mouse or when the cursor touches the screen border
        if (Input.GetMouseButton(2)) {
            pan -= new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")) * dragPanSpeed * Time.deltaTime;
        } else {
            var border = Vector2.zero;
            if (Input.mousePosition.x < panBorder) border.x -= 1f;
            if (Input.mousePosition.x >= Screen.width - panBorder) border.x += 1f;
            if (Input.mousePosition.y < panBorder) border.y -= 1f;
            if (Input.mousePosition.y > Screen.height - panBorder) border.y += 1f;
            pan += border * edgePanSpeed * Time.deltaTime;
        }

        newPosition.x += pan.x;
        newPosition.z += pan.y;

        var focusPosition = new Vector3(newPosition.x, focusHeight, newPosition.z + focusDistance);

        transform.position = newPosition;
        transform.LookAt(focusPosition);
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source