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 to Unity: Documentação e Tutoriais |
Recent posts
- 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
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
Recent Comments
@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.