现在我一直在尝试制作带有螺栓动作系统的步枪,但是要使螺栓旋转非常困难,所以问题是如何实现像 SteamVR 的循环驱动中使用的旋转动作。
自从我开始研究 Unity 的 VR 以来,我一直在使用 VRTK,它促进了许多基本机制,但如果不使用刚体,它似乎没有单轴旋转器,这可能会对小物体(如螺栓)。
我通过使用 SteamVR 中的 Circular Drive 组件找到了螺栓旋转的解决方案,如本视频所示 (6:00):https ://youtu.be/r-edgGinqZ0?t=6m
但它不适用于 VRTK,因为它的控制器不使用 SteamVR 的(手)组件,这是循环驱动器工作所需的。
PD:我有一个脚本,它有点尝试工作,但没有按预期工作:
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);
}