Log in or register to post comments

Fixing Game Objects After OnTrackingFound()

September 19, 2012 - 1:48pm #1

Hi,

 

Is there a way to "fix"the GameObject in the scene after the OnTrackingFound()?

I would like to let the player add objects to the game scene using diferents image targets. The problem is when the camera lose the tracker, then it cost a lot to creat the object again. 

So i was thinking, maybe i could instanciate them on the OnTrackingFound, and then not disable them on the OnTrackingLost().

But this didn´t work.

Any ideas?

 

Thanks

 

Matias

Fixing Game Objects After OnTrackingFound()

September 20, 2012 - 9:11am #10

You may want to place, and reset, the house target interactive, rather that with the tracking event - e.g. using Virtual Buttons or touches on screen. Otherwise it will be set immediately upon detection, not allowing the user to effectively adjust it's position. Also I'd recommend setting your World Center Mode to User and assigning the terrain target to this field. This should make it a bit easier to calculate the offset position for the model when transferring it to the terrain target.

Fixing Game Objects After OnTrackingFound()

September 20, 2012 - 7:23am #9

Thanks a lot!!!

 

I will try it and let you know

 

Regards

 

Matias

Fixing Game Objects After OnTrackingFound()

September 20, 2012 - 7:18am #8

i'm not sure if it's a good idea to do it in the OnTrackingFound function. i would do it a few frames later when you are more likely to have a good pose estimation (but just try that yourself). but in general yes, that's what i would do. except for one modification. instead of using GetComponentsInChildren i would use GetComponentInChildren to not mess up your hierarchy if that's of any importance.

best,

stefan

Fixing Game Objects After OnTrackingFound()

September 20, 2012 - 6:13am #7

You suggest doing something like this?

 

//pseudocode

private void OnTrackingFound()

    {

 

if (trackable is house trackable)

{

 

 Transform[] transforms = GetComponentsInChildren<Transform>();

 

//change parent

        foreach (Transform transform in  transforms ) {

             transform .parent = otherImigeTarget;

}

 

 

 

}

 

 

Fixing Game Objects After OnTrackingFound()

September 20, 2012 - 5:59am #6

hi,

i guess what you need is transform.parent (http://docs.unity3d.com/Documentation/ScriptReference/Transform-parent.html) to transfer the game object to another trackable.

hope this helps.

Fixing Game Objects After OnTrackingFound()

September 20, 2012 - 4:50am #5

Exactly!!!

Any idea how i can achive that?

Thanks

Matias

Fixing Game Objects After OnTrackingFound()

September 19, 2012 - 6:24pm #4

I think that you'll want to transfer the house model to the terrain target then, once its position has been established by placing the house target. That way it will be rendered in the correct position as long as the terrain target is in view, regardless of the presence of the house target. Is that what you're trying to accomplish?

 

Fixing Game Objects After OnTrackingFound()

September 19, 2012 - 2:19pm #3

Thanks for the response David,

 

Maybe i didn´t make myself clear with what my problem is.

I am developing a video game in which the whole game occurs on a terrains that loads from an image target. That works fine.

What i would like to add is another image target, a smaller printed image, in which say a house is rendered, so that the player can configure his world.

The problem with that is that, when i lose the tracking of that smaller image, it cost a lot to find it again..so maybe i was thinking of, whenever i found that kind of image, "instanciate" or "fix" the house game object to the current position of the small tracker, so that if i loose the track, the house appear instantly to where it should be...

Did i make myself clear?

 

Sory for my poor English,

Regards

Matias

 

Fixing Game Objects After OnTrackingFound()

September 19, 2012 - 2:08pm #2

 

That should be the correct approach - what are you seeing? You'll need to make the objects children of the ARCamera if you want them to maintain a fixed position relative to the ARCamera perspective.

Take a look at the DefaultTrackableEvent handler script used in the ImageTargets sample. This addresses the object's Renderer and enables/ disables this rather than instantiating and destroying the objects.

Log in or register to post comments