How can I rotate a Spatial's X and Z relative to Camera/Viewport?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FBull

Hi all,

I have a Spatial object that can be rotated on the X and Z axis using controls. The Y axis stays locked.

I’m using keys W,S to rotate it +X,-X and keys A,D to rotate it -Z,+Z

I have a camera that can spin 360 degrees around the object, orbiting it on the Y axis.

The issue is that when the camera is rotated, the controls no longer line up with how the Spatial is being rotated. (eg, the W key should always make the object rotate away from the camera, instead of to the left, etc)

What math do I need to be using to ensure that the Spatial’s X and Z rotation is relative to where the camera/viewport is in global space? I’m sure it’s quite simple in application but I’m foggy on the math of it so not sure how best to approach it.

Any suggestions are much appreciated, thanks