Scroll to Zoom in Top Down View

Grendelbiter

New member
I would like to scroll with the mouse wheel to zoom in and out gradually not in steps. Is there an easy way to do it? From discord I got a no. So I would like to request that feature. I didn't see a Feature request sub-forum for UCC so I'm posting here.
 
You can do this by changing the CameraController.AnchorOffset value based on mouse wheel input. A basic starting point:

C#:
public CameraController cameraController; // assign in inspector

void Update() {
    cameraController.AnchorOffset += Vector3.down * Input.mouseScrollDelta.y * Time.deltaTime * 10;
}

You could then apply some smoothing logic to make the movement smoother if needed. There should be plenty of resources online that explain this kind of thing, but one simple method is to lerp based on Time.deltaTime:

C#:
Vector3 anchorOffset;

void Start() {
    anchorOffset = cameraController.anchorOffset;
}

void Update() {
    anchorOffset += Vector3.down * Input.mouseScrollDelta.y * Time.deltaTime * 10;
    cameraController.AnchorOffset = Vector3.Lerp(cameraController.AnchorOffset, anchorOffset, Time.deltaTime * 0.05f);
}
 
Wouldn't the camera then be looking at some point above the character and not really at the character? Would work if it was completely top down but there is an angle (which I adjusted even further to 45 degrees)
View Distance does exactly what I want but I don't know how to access that (I'm a noob)
 
I made this little script:

Code:
using Opsive.UltimateCharacterController.Camera;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Grendelbiter
{

    public class Zoom : MonoBehaviour
    {
        [SerializeField] private float Distance = 10f;
        [SerializeField] private float zoomSensitivity = 15.0f;
        [SerializeField] private float zoomSpeed = 1.0f;
        [SerializeField] private float zoomMin = 5.0f;
        [SerializeField] private float zoomMax = 80.0f;
        [SerializeField] private CameraController controller;
        
        private float z;


        void LateUpdate()
        {
            z -= Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity;
            z = Mathf.Clamp(z, zoomMin, zoomMax);
            Distance = Mathf.Lerp(Distance, z, Time.deltaTime * zoomSpeed);
            
          
        }
    }
}

I just need to plug in Distance into View Distance.
 
It's a public property on the TopDown viewtype. So all you need to do is get a reference to the ActiveViewType, and assuming it's TopDown you can access ViewDistance:

C#:
public CameraController cameraController; // set in inspector or during Awake/Start
TopDown topDown;

...

var viewType = cameraController.ActiveViewType;
if (viewType is TopDown) {
    topDown = (TopDown)viewType;
    topDown.ViewDistance = myViewDistance;
}
 
Top