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 an object with the user gaze
Hello:
I have a sphere object and I would like to move it to re-positioning where the user is gazing. I know there is an example in the academy, but this one is enabling Spatial Mapping which enables the physics in the space (so the sphere is aware of the surrounded space and could fall to the floor, for example). I'm not looking to this.
I just need a simple way of adjust a little bit the coordinates (x and y) with the user gaze. Can I use the camera position to update the object or do I have to use the gaze manager code?
Thanks for your support.
Gus
Best Answer
-
Optionskem ✭
Hi, I have used the code below to do this. The object having this script component attached will move with your gaze and when you ari tap it will be fixed at the current location.
public class HologramPlacement : Singleton
{
////// Tracks if we have been sent a transform for the model. /// The model is rendered relative to the actual anchor. /// public bool GotTransform { get; private set; } /// <summary> /// Tracks if we have been sent a transform for the model. /// The model is rendered relative to the actual anchor. /// </summary> public bool GotTransform { get; private set; } void Start() { // Start by making the model as the cursor. // So the user can put the hologram where they want. GestureManager.Instance.OverrideFocusedObject = this.gameObject; } void Update() { if (!GotTransform) { transform.position = Vector3.Lerp(transform.position, proposeTransformPosition(), 0.2f); } } private Vector3 proposeTransformPosition() { // Put the model 2.5m in front of the user. return Camera.main.transform.position + Camera.main.transform.forward * 2.5f; } public void OnSelect() { // Note that we have a transform. GotTransform = true; // The user has now placed the hologram. // Route input to gazed at holograms. GestureManager.Instance.OverrideFocusedObject = null; }
}
5
Answers
Hi, I have used the code below to do this. The object having this script component attached will move with your gaze and when you ari tap it will be fixed at the current location.
public class HologramPlacement : Singleton
{
///
}
Be aware thar the my code got a bit distorted by formatting. I was not able to fix this.
Have you looked at the TapToPlace script that is included in the toolkit? It may already do what you want or would at least give you a place to start from.
Our Holographic world is here
RoadToHolo.com WikiHolo.net @jbienz
I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.