прямо сейчас я пытался сделать винтовку с системой затвора, но было действительно сложно сделать вращение затвора, поэтому вопрос в том, как реализовать вращающее действие, подобное тому, которое используется в SteamVR Circular Drive.
С самого начала моих исследований VR для Unity я использовал VRTK, который упрощает многие основные механики, но, похоже, у него нет вращателя одной оси без использования Rigidbody, который может иметь проблемы с небольшими объектами (например, болт).
Я нашел решение для вращения болта с помощью компонента Circular Drive из SteamVR, как показано в этом видео (6:00): https://youtu.be/r-edgGinqZ0?t=6m
Но он не будет работать для VRTK, поскольку его контроллеры не используют компонент (Hand) SteamVR, который необходим для работы Circular Drive.
П.Д .: У меня есть сценарий, который вроде пытается работать, но не так, как задумано:
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);
}