Jun
2
2015
2
2015
Dolly Zoom Effect
An article by mgear
5 Comments
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 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
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
@unitycoder_com
My TweetsSubscribe to Blog via Email
Tag Cloud
2d
3D
AI
algorithm
android
asset
build
color
custom
demo
editor
effect
error
fake
free
game
generator
greasemonkey
indie
javascript
light
line
ludumdare
mesh
paint
particles
physics
plugin
proto
prototype
script
sea
shader
shadow
sprite
terrain
texture
tutorial
ui
unity
vertex
visibility
water
waves
webgl
[…] 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.