I’ve been trying for a while to get this to work but with no luck.
What I want is for the player’s head and arm joints to rotate to face the mouse direction, while still leaving the rig itself fully animatable.
I’ve tried IK Controllers and multiple coded solutions, the one I have now being the closest I’ve gotten to a working version.
It positions the joints correctly and rotates them based on mouse direction, but the rotation is backwards for some reason.
If you look left, the joints go right and if you look up, they go down, etc.
I’ve tried using Inverse() in various parts of the code and simply reversing each part of the rotation matrix separately, but any modification at all just seems to mess up the rotation completely.
There’s a lot of other posts on making limbs face the mouse, but all either replace the joints or override them in such a way that they can’t play animations normally.
This is meant to be used with an R6 character:
local RS = game:GetService("RunService").RenderStepped
local PL = game:GetService('Players').LocalPlayer
local Mouse = PL:GetMouse()
local Char:Model = script.Parent
local Neck = Char:WaitForChild('Torso'):WaitForChild("Neck")
local RightShoulder = Char.Torso:WaitForChild("Right Shoulder")
local LeftShoulder = Char.Torso:WaitForChild("Left Shoulder")
local JointC0s = {}
local function C0_To_Point(Joint:Motor6D, PointDir:Vector3):CFrame
if not JointC0s[Joint.Name] then
JointC0s[Joint.Name] = Joint.C0
end
local Joint_C0 = JointC0s[Joint.Name]
local BaseCF = Joint.Part0.CFrame * Joint_C0
PointDir = CFrame.lookAt(BaseCF.Position, BaseCF.Position + PointDir):ToObjectSpace(BaseCF)
return CFrame.new(Joint_C0.Position) * PointDir.Rotation
end
RS:Connect(function()
local PointDir = Mouse.Origin.LookVector
Neck.C0 = C0_To_Point(Neck, PointDir)
RightShoulder.C0 = C0_To_Point(RightShoulder, PointDir)
LeftShoulder.C0 = C0_To_Point(LeftShoulder, PointDir)
end)
Any help is very appreciated as I generally am out of ideas.
Thanks.