Object following the camera with current coordinates as middle point to rotate around.

Hi guys,

I’m using Vuforia tags to (virtually) load a cube that follows the camera using the following (javascript) script:

 var target : Camera;


function Update() { 
   
    var n = target.transform.position - transform.position; 
    transform.rotation = Quaternion.LookRotation(n) * Quaternion.Euler(0, 0, 0); 
    transform.eulerAngles.z = 0;

}

this works perfectly well if the middle point of the tag and the cube are alligned. However I want the cube to rotate around its own center while the middle points of the tag and cube are NOT alligned.

Using this script, with unalligned middle points, the cube will turn around the middlepoint of the tag because the cube is a child of the tag.

Thus, my question: how can I make the cube follow the camera, while the centers of the tag and cube are not alligned and the cube is a child of the tag?

Hope everything is clear.

Thanks

Nevermind, I figured it out!

For people with a similar problem:

I made an empty game object as child of the marker. I displaced this empty gameobject to the desired position using the coordinates in the inspector. Then I made the actual cube a child of that empty game object to ensure that the coordinates of the cube are 0,0,0 and therefore the script makes it turn around it own mid point.

Feel free to ask if this is not clear.