How do I lock hand movement through script in Unity oculus vr
I'm making a game for the Oculus Quest and I want to implement a swordfighting mechanic that isn't simply flail around to win. I really want the player to feel the hits they make. This means that a sword shouldn't simply pass through the opponent, but stop when you hit him, as if you were hitting him with a real sword. The problem is that I don't know how I can make it so that the sword stops, while the hand continues to swing.
There is also the problem that the sword should be able be pulled out again in the opposite direction of the entrance direction.
I've tried using NewtonVR to simulate the physics interactions, however this package doesn't seem to work with the Oculus Quest.
I've now resorted to writing a script that I can preferably put on my sword, to disable the movement of the sword.
I'm using Unity version 2019.1.0f2 and I'm using the Oculus integration package to arrange the 6dof tracking. This means that the hands are controlled by the OVRPlayerController prefab and the grab scripts are OVRGrabber and OVRGrabbable (on the hands and sword respectively).
So my question is: "How do I stop the movement of the sword I have in my hand, when it collides with something, using Oculus VR?"
Answer by Dark-Table · Sep 02, 2019 at 03:26 PM
The sword shouldn't be directly attached to the transform of the player hand in Oculus camera rig. Basically the sword should be chasing the player's hand position. There's an event on OVRCameraRig called "UpdatedAnchors." You can subscribe to that to get notified of the hands current position every frame and move to that position if the sword isn't hitting anything.
Red Matter is a good example of a similar mechanic. They also provide haptic feedback as your real hand moves away from the VR hand's locked position.