How to Rotate Object Without Going Off-Axis?

Okay, so I followed a tutorial by Matt Aspland about how to rotate an object that you pick up and look at (right in front of the camera). This code is in the player blueprint. But the problem is, after rotating the object for just a short period of time, it quickly goes off its axis. I want to limit its rotation so that it says right side up while rotating it. Think of Overwatch, when you look at the heros’ weapons. You are able to rotate the weapons on the x (side to side) to look at the sides and on the z (up and down) to look at the top and botton. But the weapon never rotates off its axis. So, using the rotation system I set up (or one that does the same thing), can someone help me “lock” the axis that’s not supposed to rotate? I’m guessing that axis is the x axis. Thank you to anyone who can help me.

That should do the trick.

Oh, I appreciate it but this only works in Unreal 5.1, I am using version 5. Do you have a way to do it in version 5?

Just use mouse x and mouse y, it’s the same thing.

Okay, I got it to work, but one more question. I notice when I rotate the object 180 degrees, the y axis is inverted. How to make it so that the axis never inverts? Or even better, how to make it so that whatever side is facing the camera will be the side the y axis controls?

You can’t do that. It will go off axis. All you can do is to limit rotation.

But somehow other games do it. Perhaps they are using a camera rotation around the object instead?

Yes.