Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

HoloToolKit lock y-axis in HandDragger

I would like to use the HandDragger.cs script to move something in my project. But I'd like to set the Y-axis transform to either, (preferably) a variable or just a static height. Admittedly, I'm very new to coding and can't exactly find which variable sets the dragged y value.

Is this code more in depth than simply locking an axis within the update dragging?
I thought it was within:
"float distanceOffset = distanceRatio > 0 ? (distanceRatio - 1f) * DistanceScale : 0;"
and tried changing the middle variable here to just a 1f, but that didn't have the desired affect.

I had used these lines of code in a different script that would do something similar;
Vector3 newPosition = Vector3.Lerp(transform.position, targetPosition, DragSpeed);
transform.position = new Vector3(newPosition.x, transform.position.y, newPosition.z);
While this worked to lock the y-axis, the script was missing a lot of the functionality that the HandDragger script had already accounted for.

This is what I think is the relevant snippit from the HandDragger.cs script;

private void UpdateDragging()
{
Vector3 newHandPosition;
currentInputSource.TryGetPosition(currentInputSourceId, out newHandPosition);

        Vector3 pivotPosition = GetHandPivotPosition();

        Vector3 newHandDirection = Vector3.Normalize(newHandPosition - pivotPosition);

        newHandDirection = mainCamera.transform.InverseTransformDirection(newHandDirection); // in camera space
        Vector3 targetDirection = Vector3.Normalize(gazeAngularOffset * newHandDirection);
        targetDirection = mainCamera.transform.TransformDirection(targetDirection); // back to world space

        float currenthandDistance = Vector3.Magnitude(newHandPosition - pivotPosition);

        float distanceRatio = currenthandDistance / handRefDistance;
        float distanceOffset = distanceRatio > 0 ? (distanceRatio - 1f) * DistanceScale : 0;
        float targetDistance = objRefDistance + distanceOffset;

        draggingPosition = pivotPosition + (targetDirection * targetDistance);

...

Thank you for your time

Answers

  • Options

    I've made my own script attached to the object, making it lock the Y-axis on -0.375:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Lock : MonoBehaviour {
    
       public float LockY = -0.375f;
    
        // Use this for initialization
        void Start () {
    
    
        }
    
        // Update is called once per frame
        void Update () {
    
            transform.localPosition = new Vector3(transform.localPosition.x, LockY, transform.localPosition.z);
        }
    }
    
  • Options

    Very interesting approach Wzrd! I have applied it and while it does accomplish the end goal, the movement is a bit laggy. It seems like while the hand drag motion is being executed, the LockY isn't constantly controlling the height. The model moves somewhat freely in reaction to the movement of the hand but then jumps back to its locked height. So the movement looks really jumpy, but it does get you around.

    I think it is worth noting, the script order (having the LockY script below the dragging script in the inspector or above) does not seem to have an affect on constantly controlling the height.

    Thank you very much for your response. While this doesn't fully answer my question, it has helped me grow in my understanding of how I can have multiple scripts attached to one thing to do similar yet different things.

    Cheers!

Sign In or Register to comment.