Skip to content

Commit

Permalink
feat(Interaction): add z axis lock for direction control grab action
Browse files Browse the repository at this point in the history
The Direction Control Secondary Grab Action now has an option to lock
the z-axis rotation with the secondary controller which can create a
better two hand holding experience.
  • Loading branch information
thestonefox committed Dec 22, 2016
1 parent ec3e21b commit eb89a13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Expand Up @@ -21,6 +21,8 @@ public class VRTK_ControlDirectionGrabAction : VRTK_BaseGrabAction
public float ungrabDistance = 1f;
[Tooltip("The speed in which the object will snap back to it's original rotation when the secondary controller stops grabbing it. `0` for instant snap, `infinity` for no snap back.")]
public float releaseSnapSpeed = 0.1f;
[Tooltip("Prevent the secondary controller rotating the grabbed object through it's z-axis.")]
public bool lockZRotation = true;

private Vector3 initialPosition;
private Quaternion initialRotation;
Expand Down Expand Up @@ -115,7 +117,15 @@ private IEnumerator RealignOnRelease()

private void AimObject()
{
var existingEularAngles = transform.rotation.eulerAngles;
transform.rotation = Quaternion.LookRotation(secondaryGrabbingObject.transform.position - primaryGrabbingObject.transform.position, secondaryGrabbingObject.transform.TransformDirection(Vector3.forward));

if (lockZRotation)
{
existingEularAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, existingEularAngles.z);
transform.rotation = Quaternion.Euler(existingEularAngles);
}

if (grabbedObject.grabAttachMechanicScript.precisionGrab)
{
transform.Translate(primaryGrabbingObject.controllerAttachPoint.transform.position - primaryInitialGrabPoint.position, Space.World);
Expand Down
1 change: 1 addition & 0 deletions DOCUMENTATION.md
Expand Up @@ -3273,6 +3273,7 @@ It's not possible to control the direction of an interactable object with a `Fix

* **Ungrab Distance:** The distance the secondary controller must move away from the original grab position before the secondary controller auto ungrabs the object.
* **Release Snap Speed:** The speed in which the object will snap back to it's original rotation when the secondary controller stops grabbing it. `0` for instant snap, `infinity` for no snap back.
* **Lock Z Rotation:** Prevent the secondary controller rotating the grabbed object through it's z-axis.

### Class Methods

Expand Down

0 comments on commit eb89a13

Please sign in to comment.