记录一些VR开发的小坑(1)---vrtk射线相关

来源:互联网 发布:多核优化 编辑:程序博客网 时间:2024/05/29 13:41

前言:U3D刚刚入行,没有做过什么大项目,所以技术也不是很强,遇到的问题网上基本都能解决,之所以开贴,也是抱着分享信息的心态,希望网络能够帮助更多朋友解决问题


正文不墨迹:

HTC有两个手柄...... 客户需求统一功能到一个手柄.... 不就是挂两个脚本的事吗...... 完活!!! 哎?....  等等........  XXXXXXXXXX.......

SimplePointer和BezierPointer都挂上就会发现... 我好像对VRTK一无所知.....

开始研究VRTK_ControllerEvents

EmitAlias()的方法里pointerPressed是负责开关射线的..

我以为我懂了.....

 WorldPointer

一脸懵逼

DestinationMarker

二脸懵逼

简单的说,WorldPointer调用子类方法时不知道应该调用哪个..

最后的解决方法是无意间写了个测试脚本。。。 然后解决了。。。

public class TheRaythree : MonoBehaviour 
{
    //成员变量
    public VRTK_SimplePointer thesimple;
    public VRTK_BezierPointer thebezier;

    private float dist = 100f;
    private  LayerMask layersToIgnore = Physics.IgnoreRaycastLayer;

    void Update () 
{
        Ray pointerRaycast = new Ray(transform.position, transform.forward);
        RaycastHit pointerCollidedWith;
        var rayHit = Physics.Raycast(pointerRaycast, out pointerCollidedWith, dist, ~layersToIgnore);

        if (pointerCollidedWith.transform != null)
        {
            if (pointerCollidedWith.transform.tag != "Ground")
                VRTK_WorldPointer.IsSimple = true;
            else
                VRTK_WorldPointer.IsSimple = false;
        }


        if (VRTK_WorldPointer.IsSimple)
        {
            thesimple.enabled = true;
            thebezier.enabled = false;
        }
        else
        {
            thesimple.enabled = false;
            thebezier.enabled = true;
        }
    }
}

实际测试结果不是很满意...

再研究出来什么会继续写.....


如果使用line Renderer的话,hit返回的point会有问题,造成射线链接点的位置不正确

原创粉丝点击