MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

InteractionInputSource TryGetPointerPosition lags behind

Open Alexees opened this issue 9 years ago • 17 comments

I've tried to implement a LineRenderer from Motion Controller origin to cursor. However, the readings from TryGetPointerPosition lag behind the actual controller's visual representations. I am pretty sure that it has to do with the difference in querying the InteractionManager. While the controllers poll InteractionManager.GetCurrentReading(), the InteractionInputSource uses the callback InteractionManager.InteractionSourceUpdated. Is this intentional? Do I have to write my own code that uses InteractionManager.GetCurrentReading() too?

Alexees avatar Oct 24 '17 13:10 Alexees

I'll look into this. It should be using the same system under it all. (I'm pretty sure it is, but I'll double check)

StephenHodgson avatar Oct 24 '17 20:10 StephenHodgson

I actually did write my own code using InteractionManager.GetCurrentReading(). And now that I draw a line from controller to cursor, I can see/ feel the lagging, since the cursor is still depending on InteractionManager.InteractionSourceUpdated.

Alexees avatar Oct 27 '17 06:10 Alexees

Yep, this sounds as expected, depending on where you're checking GetCurrentReading(). I believe checking that in Update() should match the events, but checking it in Application.onBeforeRender like the controller visualizer script does will give you a slightly different value, which explains why you originally saw the lag. (It's also possible I'm mistaken and mixing events and polling was the real culprit.)

We should probably rewrite the cursor rendering to match the controller visualizer, though the actual targeting/object focusing should definitely still happen with the current values.

That's why the visualizer script updates the position in both Update and onBeforeRender: the position in Update should be used for the game logic, while the position in onBeforeRender should be used for rendering.

keveleigh avatar Oct 27 '17 07:10 keveleigh

The problem as I see it is the discrepancy between the controller visuals, the cursor position and the return value of TryGetPointerPosition. My understanding was that TryGetPointerPosition should give me an accurate position value, but it does not. Instead it returns the value saved from InteractionSourceUpdated which is probably the same as polling GetCurrentReading() just at the time of Update being called. This is also true for the cursor position. The controllers on the other hand closely resemble the current virtual position by polling GetCurrentReading(). With a visual ray between controller and cursor you can clearly tell the difference. Futhermore, there is a clear difference between the MR Portal controller/ cursor and the in game controller/ cursor. In the portal, they're quite responsive, in Unity, not so. If I may suggest, the visuals, the return value from TryGetPointerPosition and the cursor position should all be based on GetCurrentReading(), either by polling at the beginning of the frame once for them all, or by using that function for them all. This would result in either a total lag because at the time of rendering the controller might already be somewhere else, or a difference between those three due to polling at different times during the frame, but it would be smaller than the current solution. If I'm not mistaken.

Alexees avatar Oct 30 '17 07:10 Alexees

The Toolkit still has a lag between controller and cursor ortientation. In the MR Portal Controller, Beam and Pointer are right on the spot. In Unity, The cursor lags behind the controller. Will this be addressed at some point?

Alexees avatar Nov 09 '17 10:11 Alexees

Have you tried adjusting the cursor's stabilizer on the InputManger's GaseStabilizer? I'm thinking what you're seeing is the cursor position getting smoothed out, maybe a little too much for your needs.

(Yes it works for other pointers other than the gaze, it was never renamed)

StephenHodgson avatar Nov 09 '17 15:11 StephenHodgson

That stabilizer is only used when gazing, not when using a remote controller, I checked that (at least within cursor.cs). I also removed the deltatime based lerp at the final targetposition calculation before setting the position and it still doesn't make a difference.

Alexees avatar Nov 09 '17 16:11 Alexees

I don't think I understand. What is a remote controller?

StephenHodgson avatar Nov 09 '17 16:11 StephenHodgson

Oh sorry, I sometimes confuse the words myself. I meant Motion Controller

Alexees avatar Nov 09 '17 20:11 Alexees

And it might be the pointerstabilizer which samples multiple points for precision. Just found that by accident. I'll try that tomorrow.

Alexees avatar Nov 09 '17 21:11 Alexees

Will this be addressed at some point?

Yes, it will be. I don't have a timeline for when I can jump on it, but anybody can feel free to jump on this issue and address it as outlined above.

keveleigh avatar Nov 10 '17 00:11 keveleigh

@keveleigh an idea for handling the actual input in Update could be to use the last frames onBeforeRender value of the cursor. Since that's when the user will always see it, I think that's a good solution. I mean, how is this done in the portal? Wouldn't it be easier to just match that?

Alexees avatar Nov 13 '17 12:11 Alexees

So I drew a rays over 1 sec from where the Raysteps origin and terminus are during the time the controller receives focus. I captured it while the controller pointed completely away from the debug sheet. As you can see, there are several rays drawn along the floor towards the final cursor position, kinda lerping origin and terminus. Ignore the top thick ray bunch, it's the last rays from the camera before the switch. It seems as if the origin is always Vector3.zero and the direction is Vector3.forward at the beginning (would match the initial values for the InputSourcePointer private RayStep[] rays = new RayStep[1] { new RayStep(Vector3.zero, Vector3.forward) };). I tried to find where this lerp happens but couldn't. I deleted the GazeStabilizer and this is still the result.

screenshot 9

Alexees avatar Nov 20 '17 12:11 Alexees

After further debugging I found that removing the ControllerPointerStabilizer from the SimpleSinglePointerSelector did the trick. Well, at least it went down to a 1 frame delay, which is expected because of the difference in Controller data reading for the controller and the cursor. For me this is closed if it's not considered an issue.

Alexees avatar Nov 27 '17 16:11 Alexees

Sounds like we can do some optimization here. Please leave it open.

StephenHodgson avatar Nov 27 '17 16:11 StephenHodgson

@StephenHodgson Just wanted to write a followup post as this is still open and maybe resolved already.

Alexees avatar Feb 18 '19 07:02 Alexees

Bulk closing older HTK bug. Please reopen if you can repro this issue in MRTK v2. Thanks! Yoyo

Yoyozilla avatar Apr 11 '19 21:04 Yoyozilla