EDIT2:
感谢Draco在评论中向我推荐LineRenderer
课程。
以下是帮助我在游戏世界空间中绘制光线的脚本链接:http://answers.unity3d.com/questions/1142318/making-raycast-line-visibld.html
编辑:
我在Debug.DrawRay方法中将单位长度从1更改为100,000,从黑色更改为蓝色,现在我只能看到在场景视图中绘制的光线。
Debug.DrawRay(transform.position, transform.forward, Color.blue, 100000);
此外,我现在可以通过将以下脚本应用于游戏对象LocalAvatar
>来跟踪触控器的光线。 controller_right
。
原始帖子:
我正在尝试使用Unity 5.6.1和Visual Studio C#中的Oculus VR软件包OVRAvatar
,OVRCameraRig
和OVRInput
做一些看似简单的事情。
目标:我希望从我的Oculus触摸控制器的指针中获取光线投射,并截取一个平面以将像素应用于平面的纹理。
我能够使用OVRCameraRig
像这样使用相机的光线投射拦截飞机:
void Update() {
RaycastHit hit;
Vector3 fwd = ovrCamera.transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(ovrCamera.transform.position, fwd, out hit, 10000))
{
if (hit.collider.tag == "Plane"))
{
print("Hit the plane!");
// apply some pixels to plane texture
// setPixels(plane.texture)
}
}
// EDIT: I changed the unit length from 1 to 100,000 and now I am able to see the rays drawn in the scene view only.
// NOTE: this line below does not work in Unity's scene view or game view
Debug.DrawRay(ovrCamera.transform.position, ovrCamera.transform.forward, Color.black, 1);
}
除了Debug.DrawRay
函数不起作用之外,检查OVRcamera的光线投射到飞机上的代码确实有效。
但是,现在我正试图测试来自OVRInput.Controller.RTouch
的光线投射,我无法看到所绘制的光线并且未触发命中对撞机检查。
我已将此脚本作为组件添加到OVRCameraRig's RightHandAnchor
:
void Update() {
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, out hit, 10000))
{
if (hit.collider.tag == "Plane")
{
print("Hit plane with touch controller's raycast!");
}
}
// EDIT: I changed the unit length from 1 to 100,000 and now I am able to see the rays drawn in the scene view only.
// NOTE: this line below does not work in Unity's scene view or game view
Debug.DrawRay(transform.position, transform.forward, Color.black, 1);
}
毋庸置疑,Debug.DrawRay
功能在这里也不起作用。我不知道是否实际上正在跟踪来自触摸控制器的光线投射。
感谢任何帮助或见解,谢谢!
答案 0 :(得分:0)
感谢Draco在评论中向我推荐了LineRenderer类。
以下是帮助我在游戏世界空间中绘制光线的脚本链接:http://answers.unity3d.com/questions/1142318/making-raycast-line-visibld.html
我在Debug.DrawRay方法中将单位长度从1更改为100,000,从黑色更改为蓝色,现在我只能看到在场景视图中绘制的光线。
Debug.DrawRay(transform.position, transform.forward, Color.blue, 100000);
此外,我现在能够通过将以下脚本应用于游戏对象LocalAvatar>来跟踪触摸控制器的光线。 controller_right。