I been currently developing a gun system that uses the actual character instead of a seperate viewmodel for animations. An issue that popped up is that when looking up and down the gun shifts up or down relative to the camera, this is a problem when aiming because it shifts the sights away from the center.
What i currently have to fix it is:
local aimPart = char.Deagle:FindFirstChild("AimPart")
--Gets difference in position between the camera and an aim part in the weapon
local diff = workspace.CurrentCamera.CFrame:ToObjectSpace(aimPart.CFrame).Position
if char:GetAttribute("Aiming") then
adjustment += diff.Y
else
adjustment = 0
end
char.RightUpperArm.RightShoulder.C0 = CFrame.new(0.926, 0.548 -adjustment, 0.043) * CFrame.Angles(-x + x/2, 0, 0)
char.LeftUpperArm.LeftShoulder.C0 = CFrame.new(-0.926, 0.548 - adjustment, 0.043) * CFrame.Angles(-x + x/2, 0, 0)
This gets the difference in position between the camera and aim part and adjusts the arm’s motor C0 y position such that the difference becomes 0, this works fine but this sets the adjustment instantly, which doesn’t look good when switching between aiming and not aiming (I set the adjustment to 0 when not aiming). I want the transition to be smooth and i want the transition time to be configurable so that i cam match it with the gun’s aim time.
The problem is that when using springs or lerping, it breaks down due to the fact that the adjustment is affecting the arms, which then affects the adjustment value in a feedback loop, this causes stuttering and oscillations.
VIdeo of what happens when i try any sort of lerping:
Is there a way to either smoothly transition the value without issue, or to get the difference in such a way that it doesnt cause a feedback loop?