Jun
2
2015
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
- Adding Real World Location to Ice Fishing Prototype
- [web tool] Image Channel Inspector : AlphaScope
- Editor Tool: Smart Recompile (don’t recompile if edit comments)
- Editor Tool: Scene Size Analyzer
- LudumDare 60: Old Tech
- uBasic Scripting Language for Unity
- GreaseMonkey+Editor Plugin: 1-Click Copy script from ChatGPT (Web) to Unity Editor (as script)
- Editor Tool: Property Watcher
- .unityignore : Hide files from Project window
- PostBuild Script to Create Single exe Standalone File
- Game Loop Designer
- Favorites in PackageManager
Recent Comments
Support my work at Bags.fm:
Coin:
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
Subscribe to Blog via Email
Tag Cloud
2d
3D
AI
algorithm
android
asset
build
color
custom
demo
editor
effect
fake
free
game
generator
greasemonkey
indie
javascript
light
line
ludumdare
ludum dare
mesh
paint
particles
physics
plugin
proto
prototype
script
sea
shader
shadow
sprite
terrain
texture
tool
tutorial
ui
unity
vertex
visibility
water
waves
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.