As the title says I’d like to know how I can make the player rotate on only two axis for not make it having awkward positions as in this gif when I aim down or up.
I’ve been thinking about converting the local rotation to global and then evaluate if it’s facing down or up. If you have a better idea suggest one please.
@internetExplorerchad Bit of a late response but this might work, I would recommend locking the Z axis I believe it is. I don’t remember how to do that off the top of my head but ill see what I can find.
If you don’t mind some vector math, you could also calculate the yaw and pitch of the character-to-mouse vector and rotate using those angles. That gives you some finer control of the rotations, allowing you to set min and max pitch angles (e.g. you could limit the player to only looking 80 degrees upwards or downwards). Both angles can be calculated this way:
local vector = mouse.Hit.p - char.HumanoidRootPart.Position
local yaw = math.atan2(-vector.X, -vector.Z)
local pitch = math.acos(vector.Unit:Dot(Vector3.new(0, -1, 0))) - math.pi / 2
Then after adjusting for minimum/maximum values, you could rotate the character every frame like so: