Search Unity

Reducing 'jitter' or 'jumpiness' of your virtual objects using Vuforia

Discussion in 'AR/VR (XR) Discussion' started by eco_bach, Feb 14, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Are there ways to reduce the amount of movement or 'jitter' of your virtual objects when using Vuforia?

    Even with a well lit default target (stones in this case), with a static camera and static target there is noticeable 'jumpiness' or jitter of my virtual objects in Unity.
     
    Last edited: Feb 14, 2017
  2. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    72
    I don't know how it is now, but in previous versions of vuforia what I did was avoid using the prefab GameObject (the one with the jitter) to render the geometry, but using another GameObject which followed the Transform of the original GO, but with some interpolation.

    To show or hide the geometry like the original did, replace or update DefaultTrackableEventHandler, with a custom Monobehaviour that implements ITrackableEventHandler (or the current equivalent that says "it's tracking/it's not tracking")
     
  3. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Thanks! So in Vuforia there are 2 prefabs, one for the trackable image target and the other for the camera.
    And you make your virtual object(GameObject) you want to render as a child of the ImageTarget Prefab.
    I think it is this child GameObject you are referring to, which doesn't need to be a prefab
     
  4. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    72
    That would be the child, yes. Although, rather than making a child of the ImageTarget, which would still move with jitter, I'd make it an independent GameObject which follows that ImageTarget with interpolation.

    The interpolation would be something like:

    myPosition = Mathf.SmoothStep(myPosition, imageTargetPosition, strength);

    Which IIRC would have to be done for each component of the position's Vector3. Strength would be a float, could be Time.deltaTime * some float to modulate the intensity.

    Depending on the strength of the interpolation you would trade off between exact position and smoothness.
     
    DemonFangZ and perrygarg like this.
  5. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Last edited: Feb 15, 2017
    perrygarg likes this.
  6. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    72
    Yes, it is a little floaty if it takes too long. Try adjusting the speed to be very fast, it'll be less jittery than the original at least.

    You can interpolate the rotation too. Quaternions in Unity have slerp, you can use it like this:

    newObject.transform.rotation = Quaternion.Slerp(imageTarget.transform.rotation, newObject.transform.rotation, strength);
     
  7. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Thanks, have it working.
     
  8. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    72
    Great! Glad to be of help.
     
  9. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    On my target device, Samsung TAB S2 I notice that my virtual object seems to drift towards the image target, giving the appearance that it is floating.
    I'm wondering if another possible solution is to somehow lock its position to the image target the moment it becomes visible?
     
  10. DrBlort

    DrBlort

    Joined:
    Nov 14, 2012
    Posts:
    72
    You can, although there will be drifting over time, and if the marker leaves the camera when you get back it won't probably be in the same place.

    If that happens you can either make it jump or interpolate again.
     
  11. Nicks2580

    Nicks2580

    Joined:
    Mar 21, 2018
    Posts:
    5
    still facing floating thing can you please explain your answer with code.Thanks in advance
     
  12. seanbiganski

    seanbiganski

    Joined:
    Aug 17, 2016
    Posts:
    31
    Sorry to resurrect an old thread but this is exactly what I am trying to solve. When I instantiate a new object instead of just parenting the 3D object to the target in the scene, it's position/rotation is still parented somehow. It's not parented in the hierarchy and I tried different options like instantiate in world space.
     
  13. gringofxs

    gringofxs

    Joined:
    Oct 14, 2012
    Posts:
    240
    where i put the script?
    in AR camera?
     
  14. seanbiganski

    seanbiganski

    Joined:
    Aug 17, 2016
    Posts:
    31
    I actually didn’t end up implementing this. Instead, I tweaked my target image and rebuilt in vuforia. It still jitters at times but I’m convinced it has to do with a shine coming off of the wine bottle target.
     
  15. perrygarg

    perrygarg

    Joined:
    Jun 11, 2014
    Posts:
    2
    Thanks for this, saved my day :)
     
  16. perrygarg

    perrygarg

    Joined:
    Jun 11, 2014
    Posts:
    2
    Thanks for this, saved my day. Thanks for starting this thread :)
     
  17. naveinrex97

    naveinrex97

    Joined:
    Oct 6, 2019
    Posts:
    3
    Alright so where to put this script ?