{"id":3875,"date":"2015-06-02T09:42:32","date_gmt":"2015-06-02T06:42:32","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=3875"},"modified":"2015-06-02T09:42:32","modified_gmt":"2015-06-02T06:42:32","slug":"dolly-zoom-effect","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2015\/06\/02\/dolly-zoom-effect\/","title":{"rendered":"Dolly Zoom Effect"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/06\/dolly_zoom_effect_unity.gif\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3876\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2015\/06\/02\/dolly-zoom-effect\/dolly_zoom_effect_unity\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/06\/dolly_zoom_effect_unity.gif?fit=680%2C350&amp;ssl=1\" data-orig-size=\"680,350\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"dolly_zoom_effect_unity\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/06\/dolly_zoom_effect_unity.gif?fit=680%2C350&amp;ssl=1\" class=\"alignnone size-full wp-image-3876\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/06\/dolly_zoom_effect_unity.gif?resize=680%2C350\" alt=\"dolly_zoom_effect_unity\" width=\"680\" height=\"350\" \/><\/a><\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Dolly_zoom\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Dolly_zoom<\/a><\/p>\n<p>This version only works when target is directly at front (towards z), also viewWidth is manually given..(see for formula on that wikipage)<\/p>\n<p>Source: (attach to camera)<\/p>\n<style>.gist table { margin-bottom: 0; }<\/style>\n<div style=\"tab-size: 8\" id=\"gist22994424\" class=\"gist\">\n<div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n<div class=\"gist-data\">\n<div class=\"js-gist-file-update-container js-task-list-container\">\n<div id=\"file-dollyzoom-cs\" class=\"file my-2\">\n<div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-c  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"DollyZoom.cs content, created by unitycoder on 06:39AM on June 02, 2015.\"\n    ><\/p>\n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n<p>  <template class=\"js-file-alert-template\"><\/p>\n<div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n    <span><br \/>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br \/>\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a><br \/>\n    <\/span><\/p>\n<div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters<br \/>\n<\/a>\n<\/div>\n<\/div>\n<p><\/template><br \/>\n<template class=\"js-line-alert-template\"><br \/>\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\"><br \/>\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n<\/span><\/template><\/p>\n<table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"DollyZoom.cs\">\n<tr>\n<td id=\"file-dollyzoom-cs-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n<td id=\"file-dollyzoom-cs-LC1\" class=\"blob-code blob-code-inner js-file-line\">using UnityEngine;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n<td id=\"file-dollyzoom-cs-LC2\" class=\"blob-code blob-code-inner js-file-line\">using System.Collections;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n<td id=\"file-dollyzoom-cs-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n<td id=\"file-dollyzoom-cs-LC4\" class=\"blob-code blob-code-inner js-file-line\">\/\/ http:\/\/en.wikipedia.org\/wiki\/Dolly_zoom<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n<td id=\"file-dollyzoom-cs-LC5\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n<td id=\"file-dollyzoom-cs-LC6\" class=\"blob-code blob-code-inner js-file-line\">public class DollyZoom : MonoBehaviour<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n<td id=\"file-dollyzoom-cs-LC7\" class=\"blob-code blob-code-inner js-file-line\">{<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n<td id=\"file-dollyzoom-cs-LC8\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n<td id=\"file-dollyzoom-cs-LC9\" class=\"blob-code blob-code-inner js-file-line\">    public Transform target;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n<td id=\"file-dollyzoom-cs-LC10\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n<td id=\"file-dollyzoom-cs-LC11\" class=\"blob-code blob-code-inner js-file-line\">    Camera cam;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n<td id=\"file-dollyzoom-cs-LC12\" class=\"blob-code blob-code-inner js-file-line\">    float distance = 0f;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n<td id=\"file-dollyzoom-cs-LC13\" class=\"blob-code blob-code-inner js-file-line\">    float fov = 60;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n<td id=\"file-dollyzoom-cs-LC14\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n<td id=\"file-dollyzoom-cs-LC15\" class=\"blob-code blob-code-inner js-file-line\">    float viewWidth = 10f;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n<td id=\"file-dollyzoom-cs-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n<td id=\"file-dollyzoom-cs-LC17\" class=\"blob-code blob-code-inner js-file-line\">    void Start()<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n<td id=\"file-dollyzoom-cs-LC18\" class=\"blob-code blob-code-inner js-file-line\">    {<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n<td id=\"file-dollyzoom-cs-LC19\" class=\"blob-code blob-code-inner js-file-line\">        cam = Camera.main;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n<td id=\"file-dollyzoom-cs-LC20\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n<td id=\"file-dollyzoom-cs-LC21\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n<td id=\"file-dollyzoom-cs-LC22\" class=\"blob-code blob-code-inner js-file-line\">    void Update()<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n<td id=\"file-dollyzoom-cs-LC23\" class=\"blob-code blob-code-inner js-file-line\">    {<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n<td id=\"file-dollyzoom-cs-LC24\" class=\"blob-code blob-code-inner js-file-line\">        Vector3 pos = target.transform.position;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n<td id=\"file-dollyzoom-cs-LC25\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n<td id=\"file-dollyzoom-cs-LC26\" class=\"blob-code blob-code-inner js-file-line\">        fov = cam.fieldOfView;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n<td id=\"file-dollyzoom-cs-LC27\" class=\"blob-code blob-code-inner js-file-line\">        distance = viewWidth \/ (2f * Mathf.Tan(0.5f * fov * Mathf.Deg2Rad));<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n<td id=\"file-dollyzoom-cs-LC28\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n<td id=\"file-dollyzoom-cs-LC29\" class=\"blob-code blob-code-inner js-file-line\">        pos.z = -Mathf.Abs(distance);<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n<td id=\"file-dollyzoom-cs-LC30\" class=\"blob-code blob-code-inner js-file-line\">        cam.transform.position = pos;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n<td id=\"file-dollyzoom-cs-LC31\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n<td id=\"file-dollyzoom-cs-LC32\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n<td id=\"file-dollyzoom-cs-LC33\" class=\"blob-code blob-code-inner js-file-line\">        Debug.Log(distance);<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n<td id=\"file-dollyzoom-cs-LC34\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n<\/tr>\n<tr>\n<td id=\"file-dollyzoom-cs-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n<td id=\"file-dollyzoom-cs-LC35\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n<\/tr>\n<\/table>\n<\/div><\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/unitycoder\/d5b77ddd00e5d09be1b5\/raw\/9ce0988df08505527185e6e3712f40fed551250a\/DollyZoom.cs\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a><br \/>\n        <a href=\"https:\/\/gist.github.com\/unitycoder\/d5b77ddd00e5d09be1b5#file-dollyzoom-cs\" class=\"Link--inTextBlock\"><br \/>\n          DollyZoom.cs<br \/>\n        <\/a><br \/>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3877,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[23,3],"tags":[750,50,526,189,315],"class_list":["post-3875","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-functions-unity3d","category-unity3d","tag-dolly","tag-effect","tag-fov","tag-script","tag-zoom"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/06\/dolly_zoom_effect_unity.jpg?fit=658%2C393&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-10v","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=3875"}],"version-history":[{"count":1,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3875\/revisions"}],"predecessor-version":[{"id":3878,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3875\/revisions\/3878"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/3877"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=3875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=3875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=3875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}