# Rotating by Transform3D difference glitches out

Attention Topic was automatically imported from the old Question2Answer platform.

Video showing the issue: Imgur: The magic of the Internet

I have three objects:

• purple box
• camera
• white box (child of camera)

Purple box is static, white box is slowly rotating and moving.

I’m trying to rotate camera around purple box, so white box always stays at purple position. It works up until a moment when everything breaks and I can’t figure out why (see video).

``````func _process(delta):
var t1 = Transform3D()
var t2 = Transform3D()
t1.origin = \$Purple.global_transform.origin
t2.origin = -\$Purple.global_transform.origin

var difference: Transform3D = \$Purple.global_transform * \$White.global_transform.inverse()

\$Camera.global_transform *= t1 * difference * t2
\$Camera.global_transform = \$Camera.global_transform.orthonormalized()
``````

I’m trying to figure this out for weeks now and don’t really know where to go from here. Any tips?

Make the camera a child of the white box, offset by your desired viewing distance. Then rotate the white box within your _process(delta) function with:

`whiteBox.rotate(axis,angle)`

Where axis is a normalized vector, and angle is in radians.

Since the camera will be a child of the white box, the camera will rotate when the white box rotates.

What if I can’t switch hierarchy? This is a VR project, so white box is a VR controller and camera is VR origin - controllers are required to be children of origin.

blockchan | 2023-04-17 17:54

What are you trying to achieve by rotating the VR camera around the controller? My imagination can’t produce a scenario where that would be desirable. The user experience would be chaotic. I enjoy seeing others’ perspectives, so I’m interested in knowing what the use-case is.

However, I would probably get a reference to the camera’s current parent, reparent the camera to the controller, rotate the controller as I indicated, then reparent the camera back to its original parent.

stormreaver | 2023-04-18 12:05

I’m trying to rotate player around pivot point when holding an object, so they can rotate around it using hands.

I figured this out in the end, my code was mostly good. Instead of:

``````\$Camera.global_transform *= t1 * difference * t2
``````

I did:

``````\$Camera.global_transform = difference * \$Camera.global_transform
``````

blockchan | 2023-04-21 07:05

That’s interesting. I’m glad you got it to work.

stormreaver | 2023-04-21 13:18