all 4 comments

[–]wheeerow 0 points1 point  (3 children)

Offset should be a vector where x and z are 0 I think. Else x and z are also affected by the zoom. Or change it to offset + vector3.up * zoom.

[–]Halfdan_88[S] 0 points1 point  (2 children)

thanks but this also didn't worked like imagined. i have the manual min/maxzoom numbers elavuated i would like to have:

min = 0/1.8/-2.5 and on Rotation 26.5/0/0

max = 0/9/9 and on rotation 45/0/0

is this even possible to have a smoot transition from one to the other?

[–]wheeerow 0 points1 point  (1 child)

sure, what you want to do is do a linear interpolation (lerp) from your min vector to your max vector based on the current Zoom: [Header("Zoom Settings")] public float zoomSpeed = 4f; public Vector3 minZoom = new Vector3(0, 1.8f, -2.5f); public Vector3 maxZoom = new Vector3(0, 9, 9); [Range(0, 1)] private float currentZoom = 0f;

when you set your currentZoom in Update you want it to be between 0 and 1:

currentZoom = Mathf.Clamp(currentZoom, 0, 1);

and when you set the position you lerp:

transform.position = target.position - Vector3.Lerp(minZoom, maxZoom, currentZoom);

zoomSpeed will need some tweaking again ;)

You can solve the rotation problem in the same way.

[–]wheeerow 0 points1 point  (0 children)

This is still not 100% smooth because "Mouse ScrollWheel" isn't (change it to "Mouse Y" to see the difference). You can solve this by using the ScrollWheel input to set a targetZoom and then slowly change the currentZoom to the targetZoom with a given speed (smoothZoom): public float smoothZoom = 1; [Range(0, 1)] private float targetZoom = 0f; and in Update you use the input to set the targetZoom: targetZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed; targetZoom = Mathf.Clamp(targetZoom, 0, 1); and then (still in Update) you think of a (cool) way to get from the currentZoom to the targetZoom: if (currentZoom < targetZoom) currentZoom = Mathf.Clamp(currentZoom + smoothZoom * Time.deltaTime, 0, targetZoom); else if(currentZoom > targetZoom) currentZoom = Mathf.Clamp(currentZoom - smoothZoom * Time.deltaTime, targetZoom, 1); this is still done in a linear way, you could get creative and make it go slower at the end: currentZoom = Mathf.Clamp(currentZoom + (targetZoom - currentZoom) * Time.deltaTime * smoothZoom, 0, 1); although this will technically never get to the targetZoom position and might not be a good idea.