首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于SteamVR圆盘驱动的螺栓步枪VRTK

基于SteamVR圆盘驱动的螺栓步枪VRTK
EN

Stack Overflow用户
提问于 2017-12-01 01:43:24
回答 0查看 835关注 0票数 0

现在,我一直在尝试制作一支带有螺栓动作系统的步枪,但让螺栓旋转真的很难,所以问题是如何实现像SteamVR的Circular中使用的旋转动作。

自从我开始研究Unity的VR以来,我一直在使用VRTK,它简化了很多基本的机械原理,但它似乎没有一个单轴旋转器,如果不使用刚体,它在处理小物体(如螺栓)时可能会出现问题。

我通过使用SteamVR中的圆形驱动组件找到了螺栓旋转的解决方案,如以下视频所示(6:00):https://youtu.be/r-edgGinqZ0?t=6m

但它不适用于VRTK,因为它的控制器不使用SteamVR的(手)组件,这是圆盘驱动器工作所必需的。

P.D:我有一个脚本,它试图工作,但并不像预期的那样:

代码语言:javascript
复制
 if (isUising) //If the bolt is been used...
    {

        difference = Controller.transform.position - transform.position; //Make the vector diferentiate of the position of the controller and the bolt position
        angle = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; //Have the angle in radians of the Tan of the x and y of the vector diferentiate
        angle = Mathf.Clamp(angle, 0, 65); //Clamp the angle to the max and minimum angles

        rotFrame = angle * 6 / 65; //Transform the angle to frames for the animator

        if (!boltOpen) //If bolt isint open/slided then: send rotFrame to the animator and check if the bolt is rotated to the open rotaiton or if its fully locked
        {

            BoltRotating(rotFrame);

            if (angle >= 65) //If the angle is at the opened position, make the bolt ready for sliding
            {
                readyToOpen = true;
            }
            else
            {
                readyToOpen = false;
            }

            if (allOut) //If the bolt is closed reset the allOut bool to false
            {
                gun.Bolted();
                allOut = false;
            }
        }



private void BoltRotating(float frame) //Activate rotation animation from the animator and play the animation with 0 speed and on the frame value from the angle
    {
        BoltAnimation.SetBool("Slide", false);
        BoltAnimation.Play("BoltRotation", 0, frame);
    }
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47579537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档