2
2015
Dolly Zoom Effect
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 below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
Related Posts
5 Comments + Add Comment
Leave a comment
Recent posts
- Favorites in PackageManager
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
Recent Comments
- on Mesh Exploder (sources)
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by













[…] essa a solução que um desenvolvedor no Unity encontrou para gerar um script que adiciona uma função Dolly na câmera do Unity. O nome do desevolvedor é mgear e o código pode ser copiado e aplicado diretamente na câmera no […]
[…] Dolly Zoom Effect […]
[…] Dolly Zoom Effect […]
Not working sir. Thank you for everything.
oh, a bug.. updated script.