内容へ移動
ユーザ用ツール
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
現在位置:
Home
»
wiki
»
Unity
»
Tips
»
036 CharactorControllerで坂や段差の判定を行う
トレース:
wiki:unity:tips:036
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== 036 CharactorControllerで坂や段差の判定を行う ====== ===== 概要 ===== Charactor Controller コンポーネントを使えば傾斜や段差の判定を行うことが出来ます。 [[http://docs-jp.unity3d.com/Documentation/Components/class-CharacterController.html|Unity - Unity Manual]] ==== CharactorControllerの追加 ==== メニューのComponent -> Physics -> Character Controller を選択します。 {{:wiki:unity:tips:unity_add_chctrl.png?300|}} |Slope Limit|どのくらいの傾斜の面まで登れるかを指定します| |Step Offset|どのくらいの段差の面まで登れるかを指定します| 上記を調整することで傾斜や段差の判定を変更できます。 ==== ソースコード ==== <code csharp> public class BoxScript : MonoBehaviour { CharacterController controller; Vector3 moveDirection; float fSpeed = 3.0f; float fGravity = 0.98f; void Start () { controller = GetComponent("CharacterController") as CharacterController; } void Update () { // 地に着いているか? if( controller.isGrounded ) { moveDirection = new Vector3( Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical") ); moveDirection = transform.TransformDirection( moveDirection ); moveDirection *= fSpeed; } // 重力 moveDirection.y -= fGravity * Time.deltaTime; // 移動 controller.Move( moveDirection * Time.deltaTime ); } } </code> ==== 結果 ==== {{:wiki:unity:tips:unity_add_chctrlview.png?300|}}
Permalink
wiki/unity/tips/036.txt
· 最終更新: 2015/02/23 03:16 by
step
ページ用ツール
ログイン
文書の表示
文書の先頭へ
印刷
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
oeffentlich