Abrupt end of IK

Hi everyone, today I wanted to make a door with IK animation of the player. Everything works, but I want when we leave the Part the hand smoothly returns to the original position, not as in the video, the animation is abruptly interrupted and the hand returns to the original position.

At the end of the video you can see that when I leave Part the IK animation is abruptly cut off, and I want the arm to smoothly return to its original position.

-- Make sure ReplicatedStorage and workspace are accessible
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local workspace = game:GetService("Workspace")

-- Make sure the Zone module is accessible
local Zone = require(ReplicatedStorage:WaitForChild("Zone"))

local container = script.Parent
local zone = Zone.new(container)

zone:setAccuracy(Zone.enum.Accuracy.High) -- corrected usage of setAccuracy

-- Function to handle player entering the zone
local function onPlayerEntered(player)
	-- Check if the player has a character
	local character = player.Character
	if not character then
		return
	end

	-- Check if the character has a humanoid
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		return
	end

	-- Check if IK is already in progress
	if humanoid:GetAttribute("IKInProgress") then
		return
	end

	-- Set IKInProgress attribute to prevent overlapping interactions
	humanoid:SetAttribute("IKInProgress", true)

	-- Check if IKControl exists, create if not
	local ikControl = humanoid:FindFirstChildOfClass("IKControl") or Instance.new("IKControl")
	if not ikControl:IsA("IKControl") then
		-- If IKControl couldn't be created, exit function
		humanoid:SetAttribute("IKInProgress", false)
		return
	end

	-- Attach IKControl to humanoid if not already attached
	if not ikControl.Parent then
		ikControl.Parent = humanoid
		ikControl.Type = Enum.IKControlType.Position
		-- Find LeftHand and LeftUpperArm
		local leftHand = character:FindFirstChild("LeftHand")
		local leftUpperArm = character:FindFirstChild("LeftUpperArm")
		if not (leftHand and leftUpperArm) then
			-- If LeftHand or LeftUpperArm not found, exit function
			humanoid:SetAttribute("IKInProgress", false)
			ikControl:Destroy() -- Clean up, since IKControl is not used
			return
		end
		ikControl.EndEffector = leftHand
		ikControl.ChainRoot = leftUpperArm
	end

	-- Set the IKControl target
	local doorBaseAttachment = workspace.Door and workspace.Door:FindFirstChild("Base") and workspace.Door.Base:FindFirstChild("Attachment")
	if not doorBaseAttachment then
		-- If Door or Base or Attachment not found, exit function
		humanoid:SetAttribute("IKInProgress", false)
		return
	end

	-- Enable IKControl and set target
	ikControl.Enabled = true
	ikControl.Target = doorBaseAttachment
end

local function onPlayerExited(player)
	-- Check if the player has a character
	local character = player.Character
	if not character then
		return
	end

	-- Check if the character has a humanoid
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		return
	end

	-- Check if IKControl exists, create if not
	local ikControl = humanoid:FindFirstChildOfClass("IKControl") or Instance.new("IKControl")
	if not ikControl:IsA("IKControl") then
		-- If IKControl couldn't be created, exit function
		humanoid:SetAttribute("IKInProgress", false)
		return
	end

	-- Clear the IKControl target
	ikControl.Enabled = false
	ikControl.Target = nil
	humanoid:SetAttribute("IKInProgress", false)
end

-- Connect the onPlayerEntered function to the playerEntered event of the zone
zone.playerExited:Connect(onPlayerExited)
zone.playerEntered:Connect(onPlayerEntered)

Help…pls…i don’t know what to do

When the player exists the zone, you can set SmoothTime to like 0.5 seconds. You may have to set IKControl.Enabled = true, iirc it won’t smooth if you disable it.

2 Likes

Oh, I’m sorry, but what target I should select in exit?
Or am I missing something…if so, can you please give this fixed feature?

Target = nil and Enabled = true should do the job, otherwise play around a bit with the variables


Same?

Indeed, because you still have ikControl.Enabled = false there. That’s why it’s abruptly ending.

Remove that line and it should be smoother.

Am I missing something or is this a bug…?

Ah, my bad. You should keep the target to the door handle, but set ikControl.Weight = 0. The ikControl should stay enabled.

When entering the zone, set Weight to 1 or use a distance calculation.

3 Likes

This is just what I wanted!
THANK YOU VERY MUCH!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.