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

Tagalong.cs does not tag along very well. #111

Closed richiecarmichael closed 7 years ago

richiecarmichael commented 8 years ago

With a simple sphere I associated the "SimpleTagAlong" component. It worked perfectly.

I then substituted the "SimpleTagAlong" component with the slightly more advanced "TagAlong" component. This worked fine but only for 180° of horizontal movement. Some math issues here I suspect.

Also, I would recommend that the "MaintainFixedSize" property is false by default. It took me quite some time to discover what was enlarging my game object.

Subere23 commented 8 years ago

I have played with the tag along setting for hours on end, and have never quite gotten the response I want. The windows 10 holographic metro window would be the ideal response. It has never felt close. If you have an alternative maybe you should add it here?

stbertou commented 8 years ago

I kind of agree with @Subere23, the feel is far from the win10 menu where it actually works very well !

jwittner commented 8 years ago

Anyone want to pick up this work?

Subere23 commented 8 years ago

if no one has touched it by this weekend, I will try it out and see if I can recreate @richiecarmichael results.

jwittner commented 8 years ago

I wonder if #139 is the root cause?

Subere23 commented 8 years ago

Josh this is on my plate to look into, i have been terriblt busy. I will have a few hours tonight.

On Jul 28, 2016 12:06 AM, "Josh Wittner" notifications@github.com wrote:

I wonder if #139 https://github.com/Microsoft/HoloToolkit-Unity/issues/139 is the root cause?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/HoloToolkit-Unity/issues/111#issuecomment-235801989, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3e5alqSouNX_CLxMg_aoKuQd7yWkP4ks5qaDjNgaJpZM4JK-y_ .

jwittner commented 8 years ago

@Subere23 Excellent! Think you can assign yourself?

stbertou commented 8 years ago

Hey guys I had a quick look and wrote a very simple script, so simple I called it DummyTagalong ;-) So basically it doesn't do any fancy raycast but instead it's just trying to move the game object inside a sphere that is in front of the camera. (IMO) The effect is kind of similar to the win10 menu. Here is the code as you can see it's pretty simple (would be even simpler without the gizmos drawing code)

using UnityEngine;

public class DummyTagalong : MonoBehaviour
{
    public float Radius = 1.0f;
    public float Speed = 2.0f;

    private Vector3 perfectPosition;
    private Vector3 targetPosition;
    private float initialDistanceToCamera;
    private bool displayRadius = false;
    private bool displayTargetPosition = false;

    void Start()
    {
        initialDistanceToCamera = Vector3.Distance(this.transform.position, Camera.main.transform.position);
    }

    void Update()
    {
        displayRadius = true; // display gizmos as soon as we hit play
        Vector3 currentPos = this.transform.position;
        perfectPosition = Camera.main.transform.position + Camera.main.transform.forward * initialDistanceToCamera;

        Vector3 offsetDir = currentPos - perfectPosition;
        displayTargetPosition = (offsetDir.magnitude > Radius);

        if (displayTargetPosition)
        {
            targetPosition = perfectPosition + offsetDir.normalized * Radius;
            this.transform.position = Vector3.Lerp(currentPos, targetPosition, Speed * Time.deltaTime);
        }
    }

    public void OnDrawGizmos()
    {
        Color oldColor = Gizmos.color;

        if (displayRadius)
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(perfectPosition, Radius);
        }

        if (displayTargetPosition)
        { 
            Gizmos.color = Color.green;
            Gizmos.DrawWireSphere(targetPosition, 0.1f);
        }

        Gizmos.color = oldColor;
    }
}

As I said no ray cast or anything it won't try to be smart if it collides with a spatial mapping mesh but I guess this could be added quite easily by adding collision on the camera sphere.

If you add it to a game object containing some world space canvas it should work pretty quickly. Happy to put a pull request with a test scene if someone is interested, I showed it to a designer here and he seemed happy with the result :-)

capturetag

From the screengrab above, the red sphere is the "camera attached sphere" that is always in front of the camera. If the game object center position is outside that sphere then a target position is computed (the small green sphere) and we lerp to that position. If the game object center position is already in the sphere we don't do anything.

-s

jwittner commented 8 years ago

@stbertou The SimpleTagalong component seems to create a pretty good tag along behavior that works well with collision etc. I'm down with adding an even simpler version, but don't think "dummy" is the right moniker for it as "dummy" usually refers to placeholder or mock objects. Also, by manipulating the variables on the SimpleTagalong I do believe I can get behavior very similar to yours.

I was able to get some sensible behavior out of the TagAlong component, but it took lots of tweaking of the variables, perhaps the solution here would be to create better defaults for the TagAlong behavior?

stbertou commented 8 years ago

@jwittner that may be the issue indeed ! It's indeed not that obvious what the parameters do and at least with this (very) simple version you know that the gameobject will just try to stay inside this red sphere that is always in front of the camera so I still think that's much easier to use & setup but it's up to you guys I can keep it in our internal repo, no big deal ;-)

Also on the code complexity side you can't really do simpler than that !

For the lack of collision I kind of think that UI should in fact not collide but just be rendered on top of everything using a different camera layer. It would prevent the issue when the UI is bouncing on the other side of the screen because you've just collided with a physical wall (which can happen very easily). But I could also add a toggle and automatically add the physics component to drive this red sphere and it should magically work (hopefully!).

About the name you're right I should rename it to something more appropriate, probably just EasyTagalong.

Thanks for your quick feedback!

jwittner commented 8 years ago

EasyTagalong sounds pleasant. =) I think you're onto something with the render order of the UI.

Oh, to clarify the BoxCollider used by the SimpleTagalong doesn't appear to cause collision with the world, just used to detect collision against the view frustum. The TagAlong uses rays to keep itself out of other Holograms, e.g. the SR Mesh.

NeerajW commented 8 years ago

@jwittner you are right about the box collider. @stbertou I hate debating on names but alas it is the right thing to talk about here :) I would never know SimpleTagalong Vs EasyTagalong. Both are equally non-optimal.

How about something which describes the nature of Tagalong: SphereBasedTagalong or something similar? Also when you add it, please do the test scene and readme as always :)

stbertou commented 8 years ago

Sure thing I'll put a pull request as soon as possible. SphereBasedTagalong sounds good to me!

stbertou commented 8 years ago

OK done , see https://github.com/Microsoft/HoloToolkit-Unity/pull/173

stbertou commented 8 years ago

Looks like the PR was merged, should we close this issue?

jwittner commented 8 years ago

@stbertou I don't think the TagAlong works well yet so let's leave this open until we fix TagAlong or update it's defaults to that it works as people would expect.

stbertou commented 8 years ago

sure thing

jessemcculloch commented 7 years ago

This issue is coming up on a year with no discussion or movement.

Have we resolved this issue with the Tagalong scripts, or does this need another look?

jwittner commented 7 years ago

Closing this issue as there are many tag along solutions now.