8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Unity]ARで表示されたオブジェクトには、遠くまでRayを撃て[覚書]

Posted at

Unity + Vuforia でターゲット画像上に表示されたオブジェクトをタップした時に、何か動作をさせたいときがあると思う。
普通に、CameraのScreenPointToRay()メソッドを呼び出した後に、Physics.Raycastを呼び出せばいいわけだが、全然反応しなくて困った。

気づくまでにだいぶ時間はかかったが、わかると単純なことだった。
カメラからターゲット画像上に表示されたオブジェクトまでの距離が、だいぶ遠いのである。
普段は、

	if (Physics.Raycast(ray, out hit, 100)) {
		GameObject selectedGameObject = hit.collider.gameObject;
		// ...
	}

↑のように、オブジェクトまでの距離を100〜200までぐらいを指定しているのだが、それはカメラからの距離が一定のオブジェクトだからなんとかなってるのである。
ARで表示されたオブジェクトは、もっと遠い位置にある。

とりあえず、Physics.Raycast()に指定する距離を1000ぐらいにしたらなんとかなった…というメモ。

8
9
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
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?