I want to use IK Controls to hold a gun, but instead of going directly to the attatchement while an animation is playing (walking in this case), it instead “slides” along an axis
EDIT: forgot the video lol
script.Parent.Equipped:Connect(function(mouse: Mouse)
local char = script.Parent.Parent
local hum = char:FindFirstChildOfClass("Humanoid")
for i,v in pairs(char.RightHand:GetChildren()) do
if v.Name == "RightGrip" then
v.Name = "GunGrip"
v.Part0 = hum.RootPart
end
end
local ikRightArm = Instance.new("IKControl", hum)
ikRightArm.Type = Enum.IKControlType.Transform
ikRightArm.ChainRoot = char.RightUpperArm
ikRightArm.EndEffector = char.RightHand
ikRightArm.EndEffectorOffset = CFrame.new(0,0,0)
ikRightArm.SmoothTime = 0
ikRightArm.Target = script.Parent.Handle.Target
local Rot = CFrame.Angles(0,math.rad(180),0)
local RightElbowConstraintAttachment0 = Instance.new("Attachment", char.RightUpperArm.RightElbowRigAttachment)
RightElbowConstraintAttachment0.CFrame = Rot
RightElbowConstraintAttachment0.Axis = Vector3.new(-1, 0, -0)
RightElbowConstraintAttachment0.SecondaryAxis = Vector3.new(0, 1, -0)
RightElbowConstraintAttachment0.Name = "RightElbowConstraintAttachment0"
local RightElbowConstraintAttachment1 = Instance.new("Attachment", char.RightLowerArm.RightElbowRigAttachment)
RightElbowConstraintAttachment1.CFrame = Rot
RightElbowConstraintAttachment1.Axis = Vector3.new(-1, 0, -0)
RightElbowConstraintAttachment1.SecondaryAxis = Vector3.new(0, 1, -0)
RightElbowConstraintAttachment1.Name = "RightElbowConstraintAttachment1"
local RightElbowConstraint = Instance.new("HingeConstraint", char.RightUpperArm)
RightElbowConstraint.Attachment0 = RightElbowConstraintAttachment0
RightElbowConstraint.Attachment1 = RightElbowConstraintAttachment1
RightElbowConstraint.Name = "RightElbowConstraint"
local RightWristConstraintAttachment0 = Instance.new("Attachment", char.RightLowerArm.RightWristRigAttachment)
RightWristConstraintAttachment0.CFrame = CFrame.Angles(0, 0, math.rad(-90))
RightWristConstraintAttachment0.Axis = Vector3.new(0, -0, 1)
RightWristConstraintAttachment0.SecondaryAxis = Vector3.new(-0, 1, 0)
RightWristConstraintAttachment0.Name = "RightWristConstraintAttachment0"
local RightWristConstraintAttachment1 = Instance.new("Attachment", char.RightHand.RightWristRigAttachment)
RightWristConstraintAttachment1.CFrame = CFrame.Angles(0, 0, math.rad(-90))
RightWristConstraintAttachment1.Axis = Vector3.new(0, -0, 1)
RightWristConstraintAttachment1.SecondaryAxis = Vector3.new(-0, 1, 0)
RightWristConstraintAttachment1.Name = "RightWristConstraintAttachment1"
local RightWristConstraint = Instance.new("BallSocketConstraint", char.RightHand)
RightWristConstraint.Attachment0 = RightWristConstraintAttachment0
RightWristConstraint.Attachment1 = RightWristConstraintAttachment1
RightWristConstraint.LimitsEnabled = true
RightWristConstraint.UpperAngle = 80
RightWristConstraint.Name = "RightWristConstraint"
end)
script.Parent.Destroying:Connect(function()
end)
script.Parent.Unequipped:Connect(function()
local hum = script.Parent.Parent.Parent.Character:FindFirstChildOfClass("Humanoid")
for i,v in pairs(hum.Parent:GetDescendants()) do
if v.Name == "IKControl" or v.Name == "GunGrip" or v.Name == "RightElbowConstraintAttachment0" or v.Name == "RightElbowConstraintAttachment1" or v.Name == "RightElbowConstraint" or v.Name == "RightWristConstraintAttachment0" or v.Name == "RightWristConstraintAttachment1" or v.Name == "RightWristConstraint" then
v:Destroy()
end
end
end)