I’m attempting to disable my Inverse Kinematics, and upon doing so have it ease in to the animation that’s actively playing.
Right now, what happens can be seen below; you can see towards the end of the animation it snaps up, and then returns to normal.
What I’m wondering is if it’d be possible to get the Transform thats suppose to be applied, and perhaps lerp/tween in to that, in order to smoothly transition.
My code can be seen below.
function Utilities:Kinematics(Player, Model, Arm)
local UpperArm = Model:FindFirstChild(Arm.."UpperArm")
local Shoulder = UpperArm:FindFirstChild(Arm.."Shoulder")
local Elbow = Model:WaitForChild(Arm.."LowerArm"):FindFirstChild(Arm.."Elbow")
local Wrist = Model:WaitForChild(Arm.."Hand"):FindFirstChild(Arm.."Wrist")
local UpperTorso = Model:WaitForChild("UpperTorso")
if not Player then
local Cache = self.IK_Cache[Arm]
Shoulder.C0 = Cache.Shoulder
Elbow.C0 = Cache.Elbow
self.Heartbeat:Disconnect()
self.Stepped:Disconnect()
Shoulder.C0 = Cache.Shoulder
Elbow.C0 = Cache.Elbow
return
end
self.Stepped = RunService.Stepped:Connect(function()
if self.IK_Cache then
local Cache = self.IK_Cache[Arm]
Cache.ShoulderTransform = Shoulder.Transform
Cache.ElbowTransform = Elbow.Transform
Cache.WristTransform = Wrist.Transform
end
Shoulder.Transform = CFrame.new()
Elbow.Transform = CFrame.new()
Wrist.Transform = CFrame.new()
end)
self.Heartbeat = RunService.Heartbeat:Connect(function()
local Character = Player.Character
if not Character or not Shoulder or not Elbow or not Wrist then
return
end
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Position = HumanoidRootPart.Position
if not self.IK_Cache then
self.IK_Cache = {}
end
if not self.IK_Cache[Arm] then
self.IK_Cache[Arm] = {
Shoulder = Shoulder.C0,
Elbow = Elbow.C0,
lastShoulder = Shoulder.C0,
lastElbow = Elbow.C0
}
end
local Cache = self.IK_Cache[Arm]
local UPPER_LENGTH = math.abs(Shoulder.C1.Y) + math.abs(Elbow.C0.Y)
local LOWER_LENGTH = math.abs(Elbow.C1.Y) + math.abs(Wrist.C0.Y) + math.abs(Wrist.C1.Y)
local shoulderCFrame = UpperTorso.CFrame * Cache.Shoulder
local planeCF, shoulderAngle, elbowAngle = SolveIK:Solve(
shoulderCFrame,
Position,
UPPER_LENGTH, LOWER_LENGTH
)
local shoulderAngle = UpperTorso.CFrame:toObjectSpace(planeCF) * CFrame.Angles(shoulderAngle, 0, 0)
local elbowAngle = Cache.Elbow * CFrame.Angles(elbowAngle, 0, 0)
Shoulder.C0 = Cache.lastShoulder:lerp(Cache.lastShoulder:lerp(shoulderAngle, 50 / 100), .3)
Elbow.C0 = Cache.lastElbow:lerp(Cache.lastElbow:lerp(elbowAngle, 50 / 100), .3)
self.IK_Cache[Arm].lastShoulder = Shoulder.C0
self.IK_Cache[Arm].lastElbow = Elbow.C0
end)
end