microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6.01k stars 2.12k forks source link

EyeTrackingTarget not triggering OnLookAway when passing from collider with EyeTrackingTarget to collider without #10106

Closed Walkramis closed 3 years ago

Walkramis commented 3 years ago

Describe the bug

When having two objects with colliders right next two each other, one with EyeTrackingTarget and one without. If eye gaze is passing between these two directly (meaning eye gaze raycast is hitting a collider each frame) OnLookAway will not trigger. It will only trigger when looking at another object with EyeTrackingTarget or when the eye gaze raycast is not hitting anything.

To reproduce

Steps to reproduce the behavior:

  1. Setup a basic scene with MRTK and eye tracking.
  2. Create two cubes with colliders.
  3. Add an EyeTrackingTarget to one of them and some identifiable behaviours to OnLookAtStart and OnLookAway.
  4. Position them close so the eye gaze can go between them without "missing".
  5. Observe that OnLookAway will not trigger when going from the first to the second cube.

From Looking at the code it seems LookedAtTarget is not updated if a collider is hit but LookedAtEyetarget is null (from line 263):

LookedAtEyeTarget = hitInfo.collider.transform.GetComponent<EyeTrackingTarget>();

if (LookedAtEyeTarget != null)
{
    LookedAtTarget = LookedAtEyeTarget.gameObject;
}

Expected behavior

Expected behavior would be that OnLookAway would trigger even when gaze passes directly from object with EyeTrackingTarget to one without. Code suggestion change that fixed the issue for me.

Changed:

if (LookedAtEyeTarget != null)
{
    LookedAtTarget = LookedAtEyeTarget.gameObject;
}

To:

LookedAtTarget = hitInfo.collider.transform.gameObject;

Screenshots

Current behaviour: current

Expected: expected

Your setup (please complete the following information)

Target platform (please complete the following information)

Additional context

polar-kev commented 3 years ago

Hey @Walkramis, can you submit a PR with your code changes so we can run some tests on it and see if anything breaks?

Walkramis commented 3 years ago

Sure thing! I have now added a pull request at https://github.com/microsoft/MixedRealityToolkit-Unity/pull/10127 Let me know if you need anything else :)