Log in or register to post comments

the same animated AR objects over multiple image targets

March 20, 2013 - 3:52am #5

I've developed an AR app with unity extension. It has one image target. When the trackable is found, it shows animated objects and some static objects.

In the Unity project, the hierarchy is as follows.

ImageTarget

  --> root

      ---> character

      ---> ground

      ---> bg

      .....

That is, the "root" game object has all 3d objects as its children, and it is a child of ImageTarget.

 

I want to add more image targets with the same AR objects. So, I'm trying to use transform.parent after I read some relevant postings. But it seems not quite successful.

Here is my trial.

- I have two image targets, ImageTarget for image 'A' and ImageTarget for image 'B'. 

- ImageTarget for 'A' has 'root' object mentioned above as an its child.

- When 'B' is found, 'root' object's parent is changed to 'B'

the code snippet is shown below.

 

 private void OnTrackingFound()
{
    if (mTrackableBehaviour.TrackableName == "good_01")
    {
        GameObject obj = GameObject.FindGameObjectWithTag("root");
        GameObject newParent = GameObject.FindGameObjectWithTag("good_01");
        obj.transform.parent = newParent.transform;
     }
....
 
 
I appreciate your advices on this issue.

the same animated AR objects over multiple image targets

March 20, 2013 - 4:41am #4

Hi kang,

You have not described the problem clearly.

But it seems not quite successful.

What do you mean by this? i.e. what happens?

 

If I understand correctly you want to move your "root" object to a different parent but it is not working?

A few questions to help you diagnose:

  • What actually happens?
  • What does the inspector show?
  • Have you tried this in a non-Vuforia application to show that your technique actually works?
  • Have you been to the Unity forums and checked the documentation (as this seems a basic Unity question)

The code seems to be in line with something that ought to work.  Maybe the best thing is to build a small test app, controlled by a GUI button to understand why it is not working and what is actually happening?

Finally, have you tried having two instances of root, one under each Image Target as a failsafe - does this work?

 

HTH

N

 

 

the same animated AR objects over multiple image targets

March 20, 2013 - 9:58am #3

That's how it should work:

GameObject obj = GameObject.FindGameObjectWithTag("root");

obj.transform.parent = mTrackableBehaviour.transform;
obj.transform.position = mTrackableBehaviour.transform.position;

You can not forget the position. ;)

the same animated AR objects over multiple image targets

March 20, 2013 - 8:34pm #2

Thank you so much. That is exactly what I need.

Now I can do what I want to do. ;)

 

the same animated AR objects over multiple image targets

July 25, 2018 - 1:36am #1

It is good to add rotation as well if your model rotation is not following standard.

 

GameObject obj = GameObject.FindGameObjectWithTag("root");

obj.transform.parent = mTrackableBehaviour.transform;

obj.transform.position = mTrackableBehaviour.transform.position;

obj.transform.rotation = mTrackableBehaviour.transform.rotation;

Log in or register to post comments