Ayo. I’ve been working on a gun system for a survival game I’m making, and made a post a while ago about it asking for help with arm movement here, but I’ve since moved on from where I was going with that (many thanks to CoderQwerty for his help though) and recently managed to find a better alternative.
The method I stumbled upon changes the character’s shoulder Motor6Ds in the torso to make their arms point relative to where their mouse is. I thought I’d combine this with my gun’s Motor6D to achieve the effect I wanted, but the gun seems to drift the further away it is from the default animation position, being the middle.
I don’t think I would run into this problem if I had it Motor6D’d to the arm, but unfortunately the Motor6D is located in the HumanoidRootPart, which is required for my animations to work.
The original code wasn’t mine (I edited it a little with my miniscule knowledge about math and CFrame) and didn’t know the solution for the gun drifting, so I’m asking here. Thanks!
Code
local RunService = game:GetService("RunService")
local character = game.Players.LocalPlayer.Character
local mouse = game.Players.LocalPlayer:GetMouse()
RunService.RenderStepped:Connect(function()
character.Torso["Left Shoulder"].C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), -1.55, 0)
character.Torso["Right Shoulder"].C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), 1.55, 0)
character.HumanoidRootPart.Handle.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), 0, 0)
end)