现在我一直试图用螺栓动作系统制作步枪,但是制作螺栓旋转真的很难,所以问题是如何实现像SteamVR中使用的那样的旋转动作圆形驱动器。
自从我开始研究用于Unity的VR以来,我一直在使用VRTK,这有助于提供很多基本的机制,但它似乎没有使用单轴旋转器而不使用可能存在问题的Rigidbody小物件(如螺栓)。
我找到了一个使用SteamVR中的Circular Drive组件旋转螺栓的解决方案,如本视频(6:00)所示:https://youtu.be/r-edgGinqZ0?t=6m
但它不能用于VRTK,因为它的控制器不使用SteamVR的(Hand)组件,这是圆形驱动器工作所必需的。
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);
}
答案 0 :(得分:0)
您是否看过VRTK示例中的场景021_Controller_GrabbingObjectsWithJoints?有一个轮子应该从Valve复制CircularDrive脚本的功能,该脚本称为VRTK_RotatorTrackGrabAttach。那个场景中的车轮和车门上有一个。
第h
学家