Help with 'infinite zoom'

Hi,

I’m wanting to create an infinite zoom - or at least the appearance of one. So something similar visually to (but obviously not a copy of) what monument valley 2 did here: https://streamable.com/8yez8y

I’d really appreciate any advice. I just don’t know where to start - is it e.g. about having scenes loads asynchronously to avoid any pause whilst the new one loads?

Any advice appreciated.

Thanks very much

Well, this is pretty trivial. Since the game you’re referring to is an isometric game you can easily layer the different sections on top of each other. Moving them closer or further away from the camera doesn’t change their appearance at all. The key is to not move or zoom the camera at all. So the camera and it’s properties stay fixed. All you have to do is scale up the different sections all simultaneously. Of course the section furthest from the camera is the largest one. The next one is relatively smaller, say 10%. So the third one would be only 1% of the first size and the fourth one scaled down to 0.1% of the first size. For the animation you just scale them all up at the same time. Once you reached say a scale factor of 100 you can probably remove the first section because it’s not visible anymore. At the same time you can push all sections further away from the camera so the second section takes the position of the original first one. Of course as you increase the scale and removing the largest one, you have to spawn new sections on top of all others.

There are a few things to watch out for in order to not mess up. First of all make sure the camera is looking at the origin (0,0,0)- This makes a lot things easier. So using LookAt() would be the easiest solution. You can instantiate the sections in worldspace so they are aligned with the world, and after that you could parent them to the camera. The advantage is that you can now move a section on the local z axis and it will move perfectly in relation to the camera.

I quickly [created an example][1] with a couple of section prefabs. I’ve created a [package of the example][2]. Though the only script I used is this one:

using System.Collections.Generic;
using UnityEngine;

public class InfiniteZoom : MonoBehaviour
{
    public List<Transform> sectionPrefabs;
    public float sectionSpacing = 5;
    public float scaleFactor = 0.1f;
    private List<Transform> activeSections = new List<Transform>();

    void Start()
    {
        transform.LookAt(Vector3.zero);
    }
    void AddRandomSection()
    {
        int index = Random.Range(0, sectionPrefabs.Count);
        var clone = Instantiate(sectionPrefabs[index]);
        clone.parent = transform;
        clone.localPosition = Vector3.forward * (10-activeSections.Count) * sectionSpacing;
        if (activeSections.Count > 0)
            clone.localScale = activeSections[activeSections.Count-1].localScale * scaleFactor;
        activeSections.Add(clone);
    }

    void Update()
    {
        while (activeSections.Count < 10)
            AddRandomSection();
        float scale = Mathf.Pow(2, Time.deltaTime*3);
        for (int i = activeSections.Count - 1; i >= 0; i--)
        {
            activeSections_.localScale *= scale;_

if (activeSections*.localScale.x > 1000)*
{
Destroy(activeSections*.gameObject);*
activeSections.RemoveAt(i);
for (int n = activeSections.Count - 1; n >= 0; n–)
{
activeSections[n].localPosition += Vector3.forward * sectionSpacing;
}
}
}
}
}
The rest is just proper setup of the sections and the camera. Please forgive the coder graphics :slight_smile: I’m not an artist. Note that the Text section requires TextMeshPro.
*[1]: https://bunny83.github.io/UnityWebExamples/InfiniteZoomExample/*_
*[2]: https://github.com/Bunny83/UnityWebExamples/blob/master/InfiniteZoomExample/InfiniteZoomPack.unitypackage*_

Wow! Thanks so much - that’s really so kind of you @Bunny83. Was rather dispirited about it all - can’t quite believe the effort you went to on this, not just writing an explanation, but adding code, and then on top of that a web app and the package - really unbelievably kind. I’ll look at this properly tomorrow as it’s late where I am but I just wanted to reply now to say thank you. Is there a system in unity to actually pay people for their answers? ‘Reward user’ just seems to offer points?