【发布时间】:2017-11-30 17:43:23
【问题描述】:
现在我一直在尝试制作带有螺栓动作系统的步枪,但是要使螺栓旋转真的很难,所以问题是如何实现像 SteamVR 循环驱动中使用的旋转动作。
自从我开始研究 Unity 的 VR 以来,我一直在使用 VRTK,它有助于许多基本的力学,但如果不使用 Rigidbody,它似乎没有单轴旋转器,这可能会遇到小物体的问题(就像一个螺栓)。
我通过使用 SteamVR 中的 Circular Drive 组件找到了螺栓旋转的解决方案,如视频所示 (6:00):https://youtu.be/r-edgGinqZ0?t=6m
但它不适用于 VRTK,因为它的控制器不使用 SteamVR 的(手)组件,这是循环驱动器工作所需的。
P.D:我有一个脚本,它试图工作但没有按预期工作:
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);
}
【问题讨论】:
标签: c# unity3d virtual-reality vrtk