私は現在、Oculus Rift で書いたリアルタイムの戦艦ゲームを統合しています。
通常のカメラからレイキャスティングを行っていたときは正常に機能しましたが、現在、OVRCameraRig の LeftEyeAnchor からマウスにレイキャスティングしようとしていますが、成功していません。これがコードの現在の状態です。
IEnumerator setupPlayer(){
int i = 0;
while (i < 3){
if(Input.GetKeyDown("s")){
RaycastHit hit;
Ray ray = oculusCamera.camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out hit, 2000)) {
Debug.Log ("Yay");
Vector3 shipSpawn = new Vector3 (hit.point.x, hit.point.y+0.6f, hit.point.z);
if(validPlayerPosition(shipSpawn)){//call test function here
shipClone = Instantiate (ship, shipSpawn, Quaternion.identity) as GameObject;
i++;
}
}
}
yield return null;
}
}
ヒットする場所を見つけようとして「s」キーをスパム送信しましたが、役に立ちませんでした。
次に、短いスクリプトを書き、それを LeftEyeAnchor カメラに取り付けて、その動きを追跡しようとしたところ、次のようになりました。
using UnityEngine;
using System.Collections;
public class mousetrack : MonoBehaviour {
public Camera oculusCamera;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Ray ray = oculusCamera.camera.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);
}
}
ヘッドセットを実行して移動すると、z 軸に沿ってまっすぐ外側に線を投影するだけでしたが、ヘッドセットを取り外すと、Unity シーンで円錐台が変化するのを見ることができましたが、線は静止したままでした。私自身のような問題を検索し、このスレッドに出くわしました。
https://forums.oculus.com/viewtopic.php?t=2754
caliberMengsk の修正を試みましたが、違いはありませんでした。エラーメッセージの複数のわずかに異なるインスタンスがランタイムごとに残されます。
Screen position out of view frustum (screen pos -1061.000000, 837.000000) (Camera rect 0 0 1036 502)
UnityEngine.Camera:ScreenPointToRay(Vector3)
mousetrack:Update() (at Assets/mousetrack.cs:13)
この行を指します:
Ray ray = oculusCamera.camera.ScreenPointToRay(Input.mousePosition);
さて、私は今何をすべきか途方に暮れています。私が間違っている場所についての助けをいただければ幸いです。