Hello! I’ve been having issues getting my weapon system to follow the mouse accurately. I’ve narrowed down the issue to the arm-movement portion, and I understand why it’s doing it…i’m just unsure of how to proceed. Here’s the specifics, ignore overloading functions pls:
--LocalScript inside the tool
--Creating AlignOrientation for character/HumanoidRootPart to follow mouse as well
local function setupOrientation()
CHARACTER:WaitForChild("Humanoid").AutoRotate = false
local rootAttach = Instance.new("Attachment")
rootAttach.Parent = HRP
rootAttach.Position = HRP.Position
rootAlignOrient = script.AlignOrientation:Clone()
rootAlignOrient.PrimaryAxis = HRP.Position
rootAlignOrient.PrimaryAxisOnly = true
rootAlignOrient.Attachment0 = rootAttach
rootAlignOrient.Parent = HRP
end
--Update HRP and arms positioning
mover = MOUSE.Move:Connect(function()
rootAlignOrient.CFrame = MOUSE.Hit --+Vector3.new(CFrame.Angles(math.rad(45),0,0),0,0)--CFrame.Angles(math.rad(45),0,0)
local neckJointReturn = worldCFrame(neckJoint,MOUSE.Hit)
local rightX, rightY, rightZ = TORSO["Right Shoulder"].C0:ToEulerAnglesYXZ()
TORSO["Right Shoulder"].C0 = (TORSO["Right Shoulder"].C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((MOUSE.Hit.p - MOUSE.Origin.p).unit.y))
local leftX, leftY, leftZ = TORSO["Left Shoulder"].C0:ToEulerAnglesYXZ()
TORSO["Left Shoulder"].C0 = (TORSO["Left Shoulder"].C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-MOUSE.Hit.p - -MOUSE.Origin.p).unit.y))
WEAPON_PARTS:WaitForChild("BodyMove"):FireServer(neckJointReturn, TORSO["Right Shoulder"].C0, TORSO["Left Shoulder"].C0)
end)
--ServerScript for handing Server-Wide changes to player body
game:GetService("ReplicatedStorage"):WaitForChild("WeaponParts").BodyMove.OnServerEvent:Connect(function(player, newC0, rightArm, leftArm)
player.Character:WaitForChild("Torso").Neck.C0 = newC0
player.Character.Torso["Right Shoulder"].C0 = rightArm
player.Character.Torso["Left Shoulder"].C0 = leftArm
end)
https://gyazo.com/fd3377dc407df144beb735c6d3d414db
https://gyazo.com/a25a05ecf8cb575039861c5883b971ea
In the gifs I show how the gun rotates in an almost spherical way around the mouse position. I assume this is from the use of Motor6D C0s to move the arms. I don’t entirely hate the way it rotates in a spherical shape, but when you go to the extremes of the camera angles, it really gets inaccurate: it doesn’t even point remotely close to the mouse.
I’m really stuck on how to alleviate this without doing the FakeArms thing like other systems do. Any help appreciated, thanks!