質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
ARKit

ARKitは、iPhone/iPad向けのARアプリ用フレームワーク。iOS11以降に標準搭載されています。これを用いたARアプリは、特殊なデバイスがなくてもiPhone/iPadの単眼カメラを使用して動作することが可能です。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

835閲覧

【Unity】ARでキャラクターを走らせたが地面を走っているように見えない

nakamu

総合スコア82

ARKit

ARKitは、iPhone/iPad向けのARアプリ用フレームワーク。iOS11以降に標準搭載されています。これを用いたARアプリは、特殊なデバイスがなくてもiPhone/iPadの単眼カメラを使用して動作することが可能です。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/11/20 01:22

編集2019/11/20 01:26

ARFoundationを使って行なっています。
下記の状態になったりスピードをあげるとすぐunityちゃんが小さくなります。
オクルージョンなどが原因でこういう見え方になってしまっているのでしょうか?
![イメージ説明

理想としては、下記の動画のようにしたいです。

youtube動画リンク

C#

1using System; 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.XR.ARFoundation; 6using UnityEngine.XR.ARSubsystems; 7 8[RequireComponent(typeof(ARRaycastManager))] 9public class FigureAR : MonoBehaviour 10{ 11 [SerializeField] 12 GameObject objectPrefab; 13 GameObject unitychan; 14 ARRaycastManager raycastManager; 15 // Animator コンポーネント 16 Animator animator; 17 bool flg = false; 18 bool runFlg = false; 19 bool jumpFlg = false; 20 Vector2 screenPos; 21 float rotateY; 22 23 // 設定したフラグの名前 24 private const string key_isRun = "isRun"; 25 private const string key_isJump = "isJump"; 26 27 // Start is called before the first frame update 28 void Start() 29 { 30 raycastManager = GetComponent<ARRaycastManager>(); 31 } 32 33 // Update is called once per frame 34 void Update() 35 { 36 if (Input.touchCount > 0 && !flg) 37 { 38 var touch = Input.GetTouch(0); 39 var hitResults = new List<ARRaycastHit>(); 40 if (raycastManager.Raycast(touch.position, hitResults)) 41 { 42 unitychan = Instantiate(objectPrefab, hitResults[0].pose.position, Quaternion.identity); 43 animator = unitychan.GetComponent<Animator>(); 44 animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("AnimController"); 45 flg = true; 46 } 47 } 48 49 if (flg) 50 { 51 swipeRotate(); 52 } 53 } 54 55 public void swipeRotate() 56 { 57 Touch touch = Input.GetTouch(0); 58 if (touch.phase == TouchPhase.Began) 59 { 60 screenPos = touch.position; 61 rotateY = unitychan.transform.localEulerAngles.y; 62 } 63 else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) 64 { 65 var addRotate = (touch.position.x - screenPos.x) / 30; //回転量(-1<tx<1) 66 unitychan.transform.rotation = Quaternion.Euler(0, rotateY + addRotate * -1, 0); 67 } 68 } 69 70 public void runBtn() 71 { 72 if (runFlg) 73 { 74 // RunからWaitに遷移する 75 animator.SetBool(key_isRun, false); 76 runFlg = false; 77 } 78 else 79 { 80 // WaitからRunに遷移する 81 unitychan.transform.position += unitychan.transform.forward * 1f; 82 animator.SetBool(key_isRun, true); 83 runFlg = true; 84 } 85 } 86 87 public void jumpBtn() 88 { 89 if (jumpFlg) 90 { 91 // JumpからWait or Runに遷移する 92 animator.SetBool(key_isJump, false); 93 jumpFlg = false; 94 } 95 else 96 { 97 // Wait or RunからJumpに遷移する 98 animator.SetBool(key_isJump, true); 99 jumpFlg = true; 100 } 101 } 102} 103

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

移動がアニメータの切り替え時のみでUpdateで行なってませんでした。

C#

1void Update() 2 { 3 4 if (runFlg) 5 { 6 unitychan.transform.position += unitychan.transform.forward * 0.1f * Time.deltaTime; 7 } 8 9 if (Input.touchCount > 0 && !flg) 10 { 11 var touch = Input.GetTouch(0); 12 var hitResults = new List<ARRaycastHit>(); 13 if (raycastManager.Raycast(touch.position, hitResults)) 14 { 15 unitychan = Instantiate(objectPrefab, hitResults[0].pose.position, Quaternion.identity); 16 var size = unitychan.transform.localScale; 17 unitychan.transform.localScale = new Vector3(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f); 18 animator = unitychan.GetComponent<Animator>(); 19 animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("AnimController"); 20 flg = true; 21 arrived = true; 22 } 23 } 24 25 if (flg) 26 { 27 swipeRotate(); 28 } 29 30 31 32 }

投稿2019/11/20 08:46

nakamu

総合スコア82

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問