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.

Sharing with UNET client Hololens rotation is off

dbarrettdbarrett ✭✭✭
edited September 2017 in Questions And Answers

Hello, I am working with the Sharing with Unet example and I have modified it slightly to just spawn a capsule over the network similarly to the bullets. However, I have this weird thing that happens on the HoloLens that doesn't happen in the editor. The client HoloLens view is off by 90 degrees in the x or z axis I can't really tell which one. However the y axis is still in sync.

So I have 2 HoloLens and a computer that connects via a Network Manager HUD. I have no problems joining the session or anything but, for some reason the rotation of the 2nd (client)HoloLens is off. When looking through the scene view on the computer the host and computer client are in sync. However, when I move the capsule with the Holo client the scene view shows that it is looking in a different direction and the capsule is to the left of the Holo client.

Has anyone else had any luck with this? Any insight to this would be greatly appreciated.

AR Developer

Best Answer

  • dbarrettdbarrett ✭✭✭
    Answer ✓

    Okay, so I solved this yesterday. I just didn't have time to post an answer. In my ObjectController class I basically had to call a Command to update its position on the server using the sharedAnchorTransform whenever someone was granted authority over the object. It looks something like this.

         private void Update()
        {
            if (receivedAuthority)
            {
                Vector3 objDir = transform.forward;
                Vector3 objPos = transform.position + objDir * .01f;
    
                localPosition = sharedAnchorTrans.InverseTransformPoint(objPos);
                   // localRotation = transform.localRotation;
                    CmdTransform(localPosition);
    
    
                                         }
           else if(!receivedAuthority)
            {
    
                 transform.localPosition = localPosition;
                // transform.localRotation = localRotation;
    
            }
        }
    
        public override void OnStartAuthority()
        {
            receivedAuthority = true;
        }
    
        public override void OnStopAuthority()
        {
            receivedAuthority = false;
        }
    
        [Command]
        public void CmdTransform(Vector3 position)
        {
            if (!isLocalPlayer)
            {
              localPosition = position;
              //localRotation = rotation;
    
            }
        }
    

    AR Developer

Answers

  • I've noticed that is off by the degree of where I start the two apps. Say if I start them on opposite walls it is 180 degrees off and adjacent walls it is 90 degrees or if I have them a certain distance apart starting them they are off by that much. For example if I start the application facing a wall and with the other I face the same wall but, stand on the other side of the room the holograms are off by the amount of distance apart. I hope this clarifies the problem a little more.

    AR Developer

  • @dbarrett said:
    I've noticed that is off by the degree of where I start the two apps. Say if I start them on opposite walls it is 180 degrees off and adjacent walls it is 90 degrees or if I have them a certain distance apart starting them they are off by that much. For example if I start the application facing a wall and with the other I face the same wall but, stand on the other side of the room the holograms are off by the amount of distance apart. I hope this clarifies the problem a little more.

    I've had this happen when the 2nd hololens doesn't import the world anchor correctly. It just initializes it's start position/rotation as the origin and spawns all the objects against that point.

  • But isn't it odd that the player and the anchor are in the correct position? It is only the spawned objects that are off.

    AR Developer

  • That does sound strange. What happens in the code is that PlayerController.CmdFire is called on the host/server.

    GameObject nextBullet = (GameObject)Instantiate(bullet, sharedWorldAnchorTransform.InverseTransformPoint(bulletPos), Quaternion.Euler(bulletDir));

    sets it in local space to the Shared Anchor (on the host). Once you spawn it the BulletController.Start gets called in the Client Hololens.

    transform.SetParent(SharedCollection.Instance.transform, false);

    Sets the bullet to be a child of the object that is anchored, retaining the local coordinates that the host set earlier.

    Then the animation takes place locally by transforming the velocity to make it appear that it's coming from the player that shot the bullet.

    rb.velocity = transform.parent.TransformDirection(rb.velocity);

    So if the "sharedWorldAnchorTransform" isn't anchored in the client hololens, it just sets the origin and rotation to which ever way the hololens was pointing to when the app started.

  • dbarrettdbarrett ✭✭✭
    Answer ✓

    Okay, so I solved this yesterday. I just didn't have time to post an answer. In my ObjectController class I basically had to call a Command to update its position on the server using the sharedAnchorTransform whenever someone was granted authority over the object. It looks something like this.

         private void Update()
        {
            if (receivedAuthority)
            {
                Vector3 objDir = transform.forward;
                Vector3 objPos = transform.position + objDir * .01f;
    
                localPosition = sharedAnchorTrans.InverseTransformPoint(objPos);
                   // localRotation = transform.localRotation;
                    CmdTransform(localPosition);
    
    
                                         }
           else if(!receivedAuthority)
            {
    
                 transform.localPosition = localPosition;
                // transform.localRotation = localRotation;
    
            }
        }
    
        public override void OnStartAuthority()
        {
            receivedAuthority = true;
        }
    
        public override void OnStopAuthority()
        {
            receivedAuthority = false;
        }
    
        [Command]
        public void CmdTransform(Vector3 position)
        {
            if (!isLocalPlayer)
            {
              localPosition = position;
              //localRotation = rotation;
    
            }
        }
    

    AR Developer

  • Hello,
    I have a question about the method (receivedAuthority); does that serve the same purpose as (isLocalPlayer)?

    I ask because I am also having a similar issue with my Holograms being spawned and then jumping out of sync on the other hololens.

  • receivedAuthority is just a Boolean I used to know when someone had authority over the object. The OnStartAuthority and OnStopAuthority are methods that are called when someone either gets authority over the object or releases their authority of the object. The isLocalPlayer variable just checks to see if it is the local client or the server. It is used because we don't want the server to say perform a Move function because the server isn't a player if that makes sense.

    The biggest key in getting the object to move correctly over the server is this line of code:

    localPosition = sharedAnchorTrans.InverseTransformPoint(objPos);

    When moving an object you have to tell the server that you are moving it in respect to the Shared Anchor that the two HoloLens have. This is because it is a shared coordinate. When you connect on the server, the coordinate system does not change to the server's or vice versa. Your 0,0,0 position is where you launch the app from so if the 2nd HoloLens launches somewhere else it has a different coordinate system. The Anchor basically tells the joining HoloLens where it is in space and puts it in a coordinate position based off of the actual position. Therefore, if you put everything in respect to the shared anchor's position you get the correct position on all connected HoloLens.

    AR Developer

  • hi dBarrett,
    this snippet of code
    localPosition = sharedAnchorTrans.InverseTransformPoint(objPos)
    works great for the first hololens. However, the second hololens still has all created object out of sync by about 6 inches to the left. Do you have any idea about what would be causing this?

  • dbarrettdbarrett ✭✭✭
    edited November 2017

    Are you using all of the code above? Without looking at your code it is hard to tell.

    Make sure localPosition is a [SyncVar] at the top of your script, if it is already then:

    Try starting the 2nd HoloLens on the other side of the room and possibly facing a different direction and see if the objects are offset by where you start the application. If that is not the case then I am honestly unsure why it would be off by 6 inches unless the anchors are just off by that amount for some reason.

    However, if they are offset by wherever you start the application then it sounds like you are calling the command to the host since the 1st HoloLens (Host) can see it move correctly. So it sounds like the problem is in the case that the user does not have authority over the object. Make sure you include the else if statement from above.

    You also need to make sure that you are assigning Authority and removing Authority correctly.

    AR Developer

  • Is there a way to debug these solutions without building the solution in visual studio? This would be a lot easier if I could see step by step what was happening.

  • You can build and start with debugging when you go to build and the unity debugger will be in the console of the VS studio solution of the HoloLens you deployed to. But there isn't really an easy way to do it since you can't use the editor for testing because it does not anchor.

    However, you can do a little more troubleshooting when you run two HoloLens and join as a client through the editor and you can see for sure if it is the client or not that is off.

    If you are sending commands and have debug statements inside of them, they will only display for the Host HoloLens since commands are sent to the server and the host HoloLens is the "server"

    AR Developer

  • @dbarrett You saved my project! I could kiss you! Thanks!!
    I was struggling around since 4 days with this problem.
    Thank you so much! Maybe you know how to make the movement smoother?

Sign In or Register to comment.