Hello, i was making a gun system and i wanted the weapons to be welded to the torso so it would be easier for animations, Although i have came to an issue with doing this instead of welding to the arms. I have a part of the gun system where the arms follow the camera whenever looking up and down and the weapon kinda falls farther down or up when looking in the middle rather than up or down. Heres a video of what’s happening to me.
And heres the code i used.
local Tool = char:FindFirstChildOfClass("Tool")
if Tool:FindFirstChild("Weapon") and Tool:FindFirstChild("Weapon"):FindFirstChild("Grip") then
local ToolGrip = Tool:FindFirstChild("Weapon"):WaitForChild("Grip")
ToolGrip.C0 = ToolGrip.C0:Lerp(CFrame.new(0, 0.5, 0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), 0, 0), 0.1)
end
end
also i have tried to set the position to 0, 0.5, 0 then animate but i get the same issue. And the motor6d for the tools handle is set directly in the center of the root.
Could you also add the code are you using for rotating the arms?
A rotating joint transformation like this is made up of 3 operations:
A 3D translation from the torso’s center to the point of rotation (e.g. probably just upwards)
A rotation around this point (e.g. a rotation around the X axis)
Another 3D translation relative to the rotated CFrame (e.g. outwards and up so the gun is out towards the hand and slightly above it)
You aren’t using a final offset, so if you didn’t put the Motor6 on an attachment or part in the exact right spot, you might want to try adding another offset applied after the rotation:
local toJoint = CFrame.new(0, 0.5, 0)
local jointRotation = CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), 0, 0)
local rotatedJointToHandle = CFrame.new(0, 0.2, -1.8) -- Just a guess, moves the handle up a touch and out an arm's length
ToolGrip.C0 = ToolGrip.C0:Lerp(toJoint * jointRotation * rotatedJointToHandle, 0.1)
Anyways, using all three components should get you any type of rotation you’d like, so this should work, unless your arms are rotating in a weird way.
local RS = char:WaitForChild("Torso"):WaitForChild("Right Shoulder")
local LS = char:WaitForChild("Torso"):WaitForChild("Left Shoulder")
if RS then
RS.C0 = RS.C0:Lerp(CFrame.new(1, .65, 0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), 1.55, 0, 0) , 0.1)
end
if LS then
LS.C0 = LS.C0:Lerp(CFrame.new(1, .65, 0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), 1.55, 0, 0) , 0.1)
end