How to match two objects' rotations?

I’m having a nerve-racking problem in my project regarding object rotation.

I have an actor on my level.
This actor has two static mesh components inside it, let’s call them A and B. A is the parent of B.
Below B there are multiple camera components which I can choose during gameplay. So it is something like:

| A
  | B
    | Camera1
    | Camera2

When I start my game, I’m controlling these cameras with an HTC Vive controller.
The controller changes the position and location of the B component (so it can change all cameras).

The problem comes below.

I’m placing another actor in the level to serve as a “starting point” for the camera.
I’m setting it up in the A component above by referencing it, so its values affect the children cameras.

However, when using the Vive controller, its starting location and rotation are not equal to the starting point’s ones, so I’m using a keyboard event to match B’s location and rotation to A’s.
The problem is the rotation doesn’t match.

I’m splitting both components’ rotators and subtracting each one of their axis to build the difference rotator, which I’m then adding in the keyboard event with the Add World Rotation node.

Example with random values:

A's rotation: 50, 40, 30
B's rotation: 15, 25, 5
Calculated difference: 35, 15, 25
B's rotation after adding the difference: something like 45.3543, 42.2547, 25.3854

The difference seems to be properly calculated, but the add world rotation node kind of messes the final result.
What am I doing wrong? Is there any other way to make these rotations match?

Thank you in advance for your help!

Have you tried with “AddLocalRotation” rather than Add World Rotation? Sounds like your problem might depend on using the wrong frame of reference (ie. absolute vs relative)

Thank you for the reply!
Yes, I tried with the Add Local Rotation as well. The angle changed, but it was not correct in this case too.

I’m calculating the rotation difference of the A and B using their World Rotation, so I’m thinking I need to add it in the same way as well. I’m not sure about this, but at the moment I can’t seem to be able to find a better answer… :confused:

Hi,
I think that if you want the node SetWorldRotation to work on your StaticMesh B that is attached to A, you need to set the “Rotation” under your transform category in the blueprint properties to “AbsoluteRotation”. Here’s the capture below that replicates your situation :

Thank you for your reply!

It didn’t seem to change the rotation value to the correct one…
But after searching and trying a lot, I have reached a solution. I’m leaving it here should other people need it.

It happens the angle difference calculation was messing things up.
Someone told me that angle differences shouldn’t be calculated as a standard vector, so that was the first thing I tried to change.

So I tried calculating the difference with quaternions once again. But due to my lack of knowledge about it, I wasn’t aware that the difference between two quaternions was not simply acquired by subtracting them… And after searching, I reached the correct formula for it, which is:

Quaternion to add = Destination quaternion * (Source quaternion^-1)

The ^-1 part can be accomplished using an Inverse (Quat) node.

When I set this result quaternion in the difference variable, B successfully matched A’s rotation.

I hope this helps someone!

Thank you once again!