# Move an object to a point relative to the second camera

I have two cameras, one for the UI, one for the 3d objects.

The UI camera is just a simple, perspective camera. The 3d objects camera is rotated by (30,45,0) so it displays things with an isometric view. (It's parent it rotated).

On the UI camera's canvas I have two 2D objects (images or something) with a RectTransform. These are invisible here, but they're marked as X.

What I need to do is to move the 3d object on the X/Y axis. To be super clear, I need to move it towards one of these two X objects (left or right).

For now, the camera is rotated, so it doesn't look like it's moving left/right/up/down, but it's moving to the corners (cause of the camera's rotation).

At the start it looks like:

Now I do a _3dObject.transform.DOMove(leftXObject, 3f); // DOTween lib, doesn't matter

And it moves to:

Because of the angle of the 3d camera.

What to do?!

• The functionality of the DOTween library might actually matter. From context, I assume that _3dObject.transform.DOMove(leftXObject, 3f); causes _3dObject to move toward whatever leftXObject is. Is that right? What does the 3f parameter do? Apr 12, 2017 at 22:28
• Takes a position as a parameter. It doesn't really matter. It behaves correctly right now, but it maintains the camera angle. I just need to project these two gameobject's positions to this rotated camera, so I can move the 3dobject towards one of them in this viewport, not the 2d viewport. Apr 13, 2017 at 7:14
• I think you just said it - you want to get the positions into camera space, set the x and y of the 3D objects camera-space position to the x and y of leftXObjects camera position, and then put that back into world space. Apr 13, 2017 at 15:37
• At a given point in time during a rendering frame you have your Model View Projection matrix that is sent to the video card to render or draw its primitives. Within this World to MVP matrix you might need to make a reference copy of 2 matrices here; the current MVP state, and the object of interest current world position or coordinates, then you will need another or secondary perspective matrix for your other camera with its position and orientation. You will then need to know the distance between the object and both cameras to apply the change in translation of the object... Apr 15, 2017 at 6:59
• ... to the perspective you want to the other camera. Then apply this projection matrix to your current World to MVP matrix as your new one while maintaining the original not to lose data of other primitives that don't belong to the particular object or its instance. This should update the object that you want to be update and nothing else. However depending on the handedness that is being used for the 3D Grid and the order in which you apply transformations will matter. Such as rotating first, then translating, then skewing. Order of these are important. Apr 15, 2017 at 7:02

Created a Canvas on the rotated camera, added a 3d cube (with rotation (0,0,0)) as a parent of an empty gameobject with a RectTransform. Now it seems like it was the only isometric object visible (cause of the camera rotation). Next, I created two gameobjects, one on the left of the 3d one, one on the right and anchored them so it moves to the correct location on all resolutions.
The point here is to create an exact copy of the UI canvas, but for the 3d environment. If anchored correctly, they'll synchronize. Remember that you can anchor a RectTransform, not a classic Transform, so your cubes/spheres etc have to be childs of panels/buttons/empty GO's.