LoginSignup
0
1

More than 5 years have passed since last update.

【Unity×ARkit】AR空間にある3Dオブジェクトを持ち上げる

Last updated at Posted at 2018-08-26

3D空間にあるオブジェクトを持ち上げるような処理を作りたかったのですが、参考にできる記事が見当たらなかったので、自分のメモがてら残しておきます。

画面のタッチ処理は別で行ったので、ここには記載していません。

watch.gif


 Ray ray = new Ray();ray = Camera.main.ScreenPointToRay(Input.mousePosition);

 //rigidbodyの重力を消しておかないと持ってる最中に落ちていく
 MoveObject.GetComponent<Rigidbody>().useGravity = false; 

 //カメラの方向にオブジェクトを向かせる
 MoveObject.transform.LookAt(MainCamera.transform);



 //持ち上げる際のカメラからの距離と方向の計算
 //Distanceで持ち上げた時の距離の調整 inspectorで調整
 Vector3 velocity = ray.direction * Distance;

//カメラの位置にvelocityを足す
 Vector3 ObjectMovePosition = velocity + ray.origin;
}

余談

記事を調べても調べても、カメラをオブジェクトに追従させるものばかりで、オブジェクトをカメラに追従させるってものが見当たらなかったです。

確かに今まではオブジェクト中心でしたが、ARによるカメラ(人物)中心に物事が動いていくってことで新鮮でした。

以前書いたUnityでARKitに関わる記事

【Unity×ARkit】3D空間でアナログ時計を画面入力で回転

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1