Topic: Youtube Zoom Example
Hi,
Can the following effect be achieved in the opposite direction in online-maps:
https://www.youtube.com/watch?v=lzCEvlec5BE
preferably on click of a marker
Thanks,
Harish
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → Youtube Zoom Example
Hi,
Can the following effect be achieved in the opposite direction in online-maps:
https://www.youtube.com/watch?v=lzCEvlec5BE
preferably on click of a marker
Thanks,
Harish
Hello.
Something like this:
https://www.dropbox.com/s/16f5ppjem64er … 1.mp4?dl=0
Script:
using UnityEngine;
public class OppositeAnimZoom:MonoBehaviour
{
public Transform cameraTransform;
public float duration = 10;
public AnimationCurve zoomCurve = AnimationCurve.Linear(0, 0, 1, 1);
public AnimationCurve rotationCurve = AnimationCurve.Linear(0, 0, 1, 1);
public int targetZoom = 3;
private bool started;
private int startZoom;
private float time = 0;
private Vector3 originalScale;
private Transform mapTransform;
private OnlineMaps map;
private Vector3 originalPosition;
private Vector3 smoothZoomOffset;
private void OnGUI()
{
if (!started && GUILayout.Button("Start"))
{
startZoom = OnlineMaps.instance.zoom;
started = true;
}
}
private void Start()
{
map = OnlineMaps.instance;
mapTransform = map.transform;
originalPosition = mapTransform.localPosition;
originalScale = mapTransform.localScale;
Vector3 smoothZoomHitPoint = originalPosition + mapTransform.rotation * new Vector3(map.tilesetSize.x / -2 * originalScale.x, 0, map.tilesetSize.y / 2 * originalScale.z);
smoothZoomOffset = Quaternion.Inverse(mapTransform.rotation) * (originalPosition - smoothZoomHitPoint);
smoothZoomOffset.Scale(new Vector3(-1f / map.tilesetWidth, 0, -1f / map.tilesetHeight));
}
private void Update()
{
if (!started) return;
time += Time.deltaTime / duration;
if (time >= 1)
{
started = false;
}
float _zoom = startZoom - zoomCurve.Evaluate(time) * (startZoom - targetZoom);
Vector3 camAngles = cameraTransform.localRotation.eulerAngles;
camAngles.y = 180 - rotationCurve.Evaluate(time) * 360;
cameraTransform.localRotation = Quaternion.Euler(camAngles);
float offset = _zoom - (int)_zoom + 1;
Vector3 newScale = originalScale * offset;
mapTransform.localScale = newScale;
Vector3 s = newScale - originalScale;
s.Scale(new Vector3(1f / originalScale.x, 1 / originalScale.y, 1 / originalScale.z));
Vector3 p = mapTransform.rotation * new Vector3(map.tilesetWidth * s.x * smoothZoomOffset.x, 0, map.tilesetHeight * s.z * smoothZoomOffset.z);
mapTransform.localPosition = originalPosition - p;
map.zoom = (int) _zoom;
}
}
Thank you, Alex. That helped a Lot.
Infinity Code Forum → Online Maps Help → Youtube Zoom Example
Powered by PunBB, supported by Informer Technologies, Inc.