Rotate attached object in front of first person character


I’m trying to rotate an object, that I attached to my first person character, which is floating in front of the first person camera.
I use my mouse to control this. This is what I pretty much try to achieve: Sketchfab

Right now, I’m using this blueprint snippet:

However, the problem I’m facing is, that the X(Roll) part of the rotation is only working fine, when I’m facing in a specific direction.
When I turn around 90°, the object is rotated differently, because the rotation is different, relative to the world axis. I hope anyone can understand this :eek:

What I would like to achive is, that when I move the mouse in the Y direction to rotate the object, the object should always rotate around the right vector of my camera. Then I wouldn’t have the problem, that the rotation behaves differently relative to my view direction.

I hope anyone of you can help me :slight_smile:

Best regards

Im not sure, but have you tried “relative” instead of “world” rotation?

Thanks for the tip and sorry for the late answer.
I tried it with AddRelativeRotation like this

The problem is, that this method just adds a local rotation to the x-axis of the object, although the camera already is the parent of the object.

You need to figure out what axis you actually want to rotate around.
Then, transform the rotation to the basis of that axis, rotate, and transform back.
This requires some compound matrix math, and is why 3D linear algebra is actually important to game development!
I can’t write out the exact formula for you, because it depends on exactly how you’ve set up your scene graph.
However, I would assume that you want the camera as a reference. In that case, you can do the following:

  1. get world rotation of object
  2. get camera rotation
  3. invert camera rotation
  4. multiply world rotation by inverse camera rotation
  5. apply the rotate-around-X or whatever it is you want to do, camera relative
  6. multiply by the forward (non-inverse) rotation of the camera
  7. set as the world rotation of the object

Thanks for your input jwatte.
I didn’t get your approach to work. I think it was a bit too advanced for me.

I used another approach:
I still rotate around the Z-axis with my Mouse X input via “AddActorWorldLocation”.

For the rotation around the Y-axis, I attached a sphere component to my character/first person camera.
I attach the picked up object to the center of the sphere component and use “AddLocalRotation” to the Y-axis on the sphere component.
So since the picked up object is a child of the sphere component, it will rotate accordingly.

Thanks for all the answers!