内容へ移動
ユーザ用ツール
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
現在位置:
Home
»
wiki
»
Unity
»
Tips
»
039 追従するカメラ
トレース:
wiki:unity:tips:039
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== 039 追従するカメラ ====== ===== 概要 ===== GameObjectが動くとカメラもそれに従って移動します。 ==== ソースコード ==== <code csharp> using UnityEngine; using System.Collections; public class CameraScript : MonoBehaviour { GameObject target; void Start () { target = GameObject.FindGameObjectWithTag("playerTag"); } void Update () { transform.LookAt( target.transform.position ); Vector3 vecCamera = transform.position - target.transform.position; vecCamera = Vector3.Normalize( vecCamera ); float distance = 5.0f; Vector3 cameraTargetPosition = target.transform.position + vecCamera * distance; float damping = 1.0f; transform.position = Vector3.Lerp( transform.position, cameraTargetPosition, damping * Time.deltaTime ); } } </code> カメラのGameObjectに割り当てる。移動量はLerp で補間。 ==== Vector3.SmoothDampを使う場合 ==== <code csharp> Vector3 velocity = Vector3.zero; transform.position = Vector3.SmoothDamp( transform.position, cameraTargetPosition, ref velocity, damping ); </code>
Permalink
wiki/unity/tips/039.txt
· 最終更新: 2014/11/13 07:09 (外部編集)
ページ用ツール
ログイン
文書の表示
文書の先頭へ
印刷
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
oeffentlich