How to attach a 3D object to the camera on tap (World Object Template)?

I made this logic so that I could “pick up” a 3D object by tapping on it - the position of the object smoothly changes to the position of an Empty object tied to the camera.

But when I use the default World Object Template and the 3D object is inside the LoopingAnimBlock, then this logic no longer works and the 3D object takes the wrong position. How can this problem be solved?

If you are trying to set the world position of an object in patches, make sure that object doesn’t have any parents. It needs to be outside of the device (and outside of the plane tracker).

You can only set the local position of objects in patches, so setting global position necessitates a parentless object (where local == global).

Otherwise, you can set the global position in script, regardless of hierarchy.

1 Like

I tried to use the Global Transform and Local Transform patches, but it didn’t work, I think the reason is that this object is nested deep inside several parent empty objects, and I need to somehow compensate for all the offsets, which hasn’t worked yet. If there is a way to do this with a script, can I ask for any simple code example or specific documentation article about it?

Sure, here’s a script that sets the global transform on a plane that is a child of the focal distance.

const Scene = require('Scene')
const Reactive = require('Reactive') // required indirectly for reactive scripting capability

const init = (async function () {

  const [faceNull, plane0] = await Promise.all([

  plane0.worldTransform.position = faceNull.worldTransform.position

})() (8.8 KB)

1 Like

Thank you so much, this is really helpful!