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.

Moving a rigidbody with manipulation gestures

I am trying to use a GestureRecognizer to move my GameObject ManipulationObjectameObject which I've hooked up in Unity.

When I do a print statement in the PerformManipulationUpdate method, the Position value is almost always 0, or very close to it like 3E-5.

It's my understanding that the Vector3 position argument to ManipulationRecognizer_ManipulationUpdatedEvent will be the cumulative distance of the gesture, so I'm surprised it is always so small. When I apply the change to the object's position, there is no noticable change.

One thing to note is that I'm doing this in the emulator as my Hololens is out of office, so not sure if that's a factor.

Am I doing something stupid? Do I have a misunderstanding of some part of this?

Any help and pointers appreciated!

public class GestureManager : MonoBehaviour {
public GestureRecognizer ManipulationRecognizer { get; private set; }

    public Vector3 ManipulationPosition { get; private set; }

    public GameObject ManipulationObject;
    private Vector3 manipulationPreviousPosition;
    private Rigidbody rb;

    void Start()
        rb = ManipulationObject.GetComponent<Rigidbody>();            

    void Awake()
        ManipulationRecognizer = new GestureRecognizer();
        ManipulationRecognizer.ManipulationStartedEvent += ManipulationRecognizer_ManipulationStartedEvent;
        ManipulationRecognizer.ManipulationUpdatedEvent += ManipulationRecognizer_ManipulationUpdatedEvent;
        ManipulationRecognizer.ManipulationCompletedEvent += ManipulationRecognizer_ManipulationCompletedEvent;
        ManipulationRecognizer.ManipulationCanceledEvent += ManipulationRecognizer_ManipulationCanceledEvent;

    private void ManipulationRecognizer_ManipulationStartedEvent(InteractionSourceKind source, Vector3 position, Ray ray)
        rb.isKinematic = true;
        manipulationPreviousPosition = position;

    private void ManipulationRecognizer_ManipulationUpdatedEvent(InteractionSourceKind source, Vector3 position, Ray ray)

    private void ManipulationRecognizer_ManipulationCompletedEvent(InteractionSourceKind source, Vector3 position, Ray ray)
        rb.isKinematic = false;

    private void ManipulationRecognizer_ManipulationCanceledEvent(InteractionSourceKind source, Vector3 position, Ray ray)
        rb.isKinematic = false;

    void PerformManipulationUpdate(Vector3 position)
        Vector3 moveVector = Vector3.zero;
        // 4.a: Calculate the moveVector as position - manipulationPreviousPosition.
        moveVector = position - manipulationPreviousPosition;
        // 4.a: Update the manipulationPreviousPosition with the current position.
        manipulationPreviousPosition = position;

        // 4.a: Increment this transform's position by the moveVector.
        ManipulationObject.transform.position += moveVector;        

Best Answer


Sign In or Register to comment.