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.

How do you get position of the controller of with unity?

I have been using the interaction manager to connect the controllers (which are tricky as it appears I have to push windows button, go to mixed reality portal and then back to unity for it to connect, any clues how to make it connect are appreciated) and it doesn't seem to matter what I have the SourcePos never returns a position.

Can anyone get this work and if so what is the trick?

Script below

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.WSA.Input;

public class ControllerInput : MonoBehaviour {

// Use this for initialization
void Start () {

    InteractionManager.InteractionSourceDetected += InteractionManager_SourceDetected;
    InteractionManager.InteractionSourceUpdated += InteractionManager_SourceUpdated;
    InteractionManager.InteractionSourceLost += InteractionManager_SourceLost;
    InteractionManager.InteractionSourcePressed += InteractionManager_SourcePressed;
    InteractionManager.InteractionSourceReleased += InteractionManager_SourceReleased;
}

void OnDestroy()
{

    InteractionManager.InteractionSourceDetected -= InteractionManager_SourceDetected;
    InteractionManager.InteractionSourceUpdated -= InteractionManager_SourceUpdated;
    InteractionManager.InteractionSourceLost -= InteractionManager_SourceLost;
    InteractionManager.InteractionSourcePressed -= InteractionManager_SourcePressed;
    InteractionManager.InteractionSourceReleased -= InteractionManager_SourceReleased;
}
    // Update is called once per frame
void Update ()
{
    //Vector3 leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);

    //Debug.Log("LP" + leftPosition);


    var interactionSourceStates = InteractionManager.GetCurrentReading();
    Debug.Log("Num Interaction Source States: " + interactionSourceStates.Length);
    /*
    if (interactionSourceStates.selectPressed)
    {
        Debug.Log("Press" + Time.time);
    }
    */
    if (Input.GetButton("Fire1"))
    {
        Debug.Log("Fire1");
    }

}

void InteractionManager_SourcePressed(InteractionSourcePressedEventArgs args)
{

    Debug.Log("Source pressed");
}
void InteractionManager_SourceDetected(InteractionSourceDetectedEventArgs args)
{

    Debug.Log("Source detected");
}
void InteractionManager_SourceUpdated(InteractionSourceUpdatedEventArgs args)
{
    Vector3 p;
    //float a;
    args.state.sourcePose.TryGetPosition(out p);
    //a = args.state.sourcePose.positionAccuracy;

    //Debug.Log("Source updated " + p);
}
void InteractionManager_SourceLost(InteractionSourceLostEventArgs args)
{

    Debug.Log("Source lost");
}
void InteractionManager_SourceReleased(InteractionSourceReleasedEventArgs args)
{

    Debug.Log("Source released");
}

}

Answers

  • I'm also having this issue just in the MotionControllerTest scene in the MRTK

  • I am using the standard unity build

  • I find that I need to close the mixed reality portal every time before launching from unity for the controllers to work.

Sign In or Register to comment.