✓ Accepted answer
This is happening because you set the Y of the lookAt lookvector to the height of the HumanoidRootPart. This means that it will rotate the character to point towards the mouse X and Z, but still keep the same tilt angle. To fix this, you can change that Vector3 to something like this:
CFrame.new(humanoidRootPart.Position, mouse.Hit.p)
which will change to make the character look at all axes.
However, characters automatically balance themselves so that they dont tilt forwards or backwards. If you want to allow for tilting on these axes, you could set the PlatformStand property of the character's Humanoid to false.
However, this would prevent them from moving, so you might want to look into rotating the Root Motor6D instead. Using the logic from this page, you can get the equation C1 == Part1:inverse() * Part0 * C0. This means that if we want the Part1 (the torso) to have the CFrame that points to the mouse, we can calculate the C1 required for that like this:
local function FaceMouse()
local Joint = humanoidRootPart:FindFirstChildOfClass("Motor6D")
local DesiredCF = CFrame.new(Joint.Part1.Position, mouse.Hit.p)
local RequiredC1 = DesiredCF:inverse() * Joint.Part0.CFrame * Joint.C0
Joint.C1 = RequiredC1
end
Hopefully something like that works, I haven't tested it, but it should edit the Motor6D of the character so that it rotates the torso to face the mouse.
Hope this helps!
2 comments
uhh change humanoidRootPart.Position.Y --> mouse.Hit.p.Y
Thanks!