Jun
2
2015

Dolly Zoom Effect

dolly_zoom_effect_unity

http://en.wikipedia.org/wiki/Dolly_zoom

This version only works when target is directly at front (towards z), also viewWidth is manually given..(see for formula on that wikipage)

Source: (attach to camera)


using UnityEngine;
using System.Collections;
// http://en.wikipedia.org/wiki/Dolly_zoom
public class DollyZoom : MonoBehaviour
{
public Transform target;
Camera cam;
float distance = 0f;
float fov = 60;
float viewWidth = 10f;
void Start()
{
cam = Camera.main;
}
void Update()
{
Vector3 pos = target.transform.position;
fov = cam.fieldOfView;
distance = viewWidth / (2f * Mathf.Tan(0.5f * fov * Mathf.Deg2Rad));
pos.z = -Mathf.Abs(distance);
cam.transform.position = pos;
Debug.Log(distance);
}
}

view raw

DollyZoom.cs

hosted with ❤ by GitHub


5 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.