VRTK Using SteamVR Circular Drive for a bolt action rifle

946 Views Asked by At

right now I have been trying to make a rifle with bolt action system, but it have been really hard to make the bolt rotation, so the question is how to implement a rotating action like the one used in SteamVR's Circular Drive.

Since the start of my research on VR for Unity I have been using the VRTK which facilitates a lot of the basic mechanics, but it seem to don't have a one axis rotator without using Rigidbody which can have problems with small objects (like a bolt).

I found a solution for the rotation of the bolt by using the Circular Drive component from the SteamVR, like shown in this video (6:00): https://youtu.be/r-edgGinqZ0?t=6m

But it wont work for VRTK as its controllers dosen't use the (Hand) component of SteamVR which is needed for the Circular Drive to work.

P.D: I have a script which kinda tries to work but not as intended:

 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);
    }
1

There are 1 best solutions below

1
On

Have you looked at the scene 021_Controller_GrabbingObjectsWithJoints in the examples for VRTK? There's a wheel that should duplicate the functionality of the CircularDrive script from Valve, the script is called VRTK_RotatorTrackGrabAttach. There's one on the Wheel and the Door in that scene.

hth.

J.