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.

Scripting for moving a Game Object using gesture.

Greetings all,

I would like to Translate a Game Object using gesture in hololens.

I do not have to use Gaze because there is only one Game object in the scene. The Game Object will always appear in the middle of the screen as I move my head. I want to able to Translate the Game object with a pressed gesture and be able to end the Translation with a Release gesture. I am having trouble with the scripting part. Any help would be appreciated.

Thank you, Cheers

Best Answers

  • vinojanvinojan
    Answer ✓

    Hello @JannikLassahn , thanks for the reply.

    I took a look at the Handdraggable script and am still fuzzy as I am fairly new to coding. Can you give me some code samples. All I need to is to attach a simple script to a game objet where if move my hand, the game object should be able to move with my hand.

    Thank you , cheers

Answers

  • Your options:

    • Take a look at the Handdraggable script from the HoloToolkit
    • Implement the IManipulationHandler Interface (also HoloToolkit), set state/position of the object and use them in the Update method.
    • Use Unity's GestureRecognizer and manually subscibe to the Hold and Manipulation events. Then handle state/position accordingly.

    If you would like some code samples, please let me know.

  • vinojanvinojan
    Answer ✓

    Hello @JannikLassahn , thanks for the reply.

    I took a look at the Handdraggable script and am still fuzzy as I am fairly new to coding. Can you give me some code samples. All I need to is to attach a simple script to a game objet where if move my hand, the game object should be able to move with my hand.

    Thank you , cheers

  • I copy and pasted the sample code you provided me , however I got 2 errors.

    The type or namespace name ' IManipulationHandler' could not be found
    (are you missing a using directive or an assembly reference?)

    The type or namespace name 'ManipulationEventData' could not be found
    (are you missing a using directive or an assembly reference?)

    Also how would I go about getting the InputManager Prefab.

    Sorry I am completely new at this, and all you help is appreciated.

    Thank you, Cheers.

  • JannikLassahnJannikLassahn ✭✭
    edited April 2017

    Take a look at the Getting Started guide for setting up the HoloToolkit. The HoloToolkit contains the interfaces and prefabs I mentioned.
    Also, I omitted the using statements in my code sample, because your IDE can add them for you. They are:

    using HoloToolkit.Unity.InputModule;
    using UnityEngine;
    
  • @JannikLassahn said:
    The easiest would be to add the Handdraggable script to your GameObject. Everything just works ;)

    The most basic implementation for a "custom" implementation I could think of is the following:

    public class ManipulationTest : MonoBehaviour, IManipulationHandler
    {
        public void OnManipulationCanceled(ManipulationEventData eventData)
        {
        }
    
        public void OnManipulationCompleted(ManipulationEventData eventData)
        {
        }
    
        public void OnManipulationStarted(ManipulationEventData eventData)
        {
        }
    
        public void OnManipulationUpdated(ManipulationEventData eventData)
        {
            transform.position += eventData.CumulativeDelta;
        }
    }
    
    

    One could tweak the drag behaviour by multiplying values to eventData.CumulativeDelta. Also remember that you have to add the InputManager Prefab to the scene for this to work.

    this would work(i didn't test, just for feeling), but there is one flaw, this will work only when the Gaze is on the object the script is attached to it, once the gaze moving away from the object, the IManipulationHandler will stop working

Sign In or Register to comment.