Hey guys! I hope you all do very very well! Being direct, I was testing a script of inverse kinematics, but I got a problem, and It’s that when the player is starting to walk around the arm doesnt point ot the target anymore:
-Here’s the video:
I don’t really know how to fix this, and I’ll be VERY grateful with you and your heart if you can give me a hand with this, I don’t really know how to fix this, thanks for reading and have a nice day!
My goal is to make the arm move with inverse kinematics while the player/character is moving.
Heres the script (ModuleScript/Client)
local IK = {}
local function solveArm(originCFrame,targetPosition,a,b)
local localized = originCFrame:pointToObjectSpace(targetPosition)
local localizedUnit = localized.unit
local l3 = localized.magnitude
local axis = Vector3.new(0, 0, -1):Cross(localizedUnit)
local angle = math.acos(-localizedUnit.Z)
local planeCF = originCFrame * CFrame.fromAxisAngle(axis, angle)
if l3 < math.max(b, a) - math.min(b, a) then
return planeCF * CFrame.new(0, 0, math.max(b, a) - math.min(b, a) - l3), -math.pi/2, math.pi
elseif l3 > a + b then
return planeCF * CFrame.new(0, 0, a + b - l3), math.pi/2, 0
else
local a1 = -math.acos((-(b * b) + (a * a) + (l3 * l3)) / (2 * a * l3))
local a2 = math.acos(((b * b) - (a * a) + (l3 * l3)) / (2 * b * l3))
return planeCF, a1 + math.pi/2, a2 - a1
end
end
function IK.BuildPacketArms(character)
local packet = {}
packet.character = character
packet.upperTorso = character:WaitForChild("UpperTorso")
packet.rightUpperArm = character:WaitForChild("RightUpperArm")
packet.rightLowerArm = character:WaitForChild("RightLowerArm")
packet.rightShoulder = packet.rightUpperArm:WaitForChild("RightShoulder")
packet.rightElbow = packet.rightLowerArm:WaitForChild("RightElbow")
packet.rightShoulderInit = packet.rightShoulder.C0
packet.rightElbowInit = packet.rightElbow.C0
packet.rightWrist = character:WaitForChild("RightHand"):WaitForChild("RightWrist")
return packet
end
function IK.Arms(packet, target)
local SHOULDER_C0_CACHE = packet.rightShoulder.C0
local ELBOW_C0_CACHE = packet.rightElbow.C0
local UPPER_LENGTH = math.abs(packet.rightShoulder.C1.Y) + math.abs(packet.rightElbow.C0.Y)
local LOWER_LENGTH = math.abs(packet.rightElbow.C1.Y) + math.abs(packet.rightWrist.C0.Y) + math.abs(packet.rightWrist.C1.Y)
local shoulderCFrame = packet.upperTorso.CFrame * SHOULDER_C0_CACHE
local goalPosition = target.Position
local planeCF, shoulderAngle, elbowAngle = solveArm(shoulderCFrame, goalPosition, UPPER_LENGTH, LOWER_LENGTH)
local goalRightShoulderC0CFrame = packet.upperTorso.CFrame:toObjectSpace(planeCF) * CFrame.Angles(shoulderAngle, 0, 0)
packet.rightShoulder.C0 = goalRightShoulderC0CFrame.Rotation + packet.rightShoulder.C0.Position
packet.rightElbow.C0 = packet.rightElbowInit * CFrame.Angles(elbowAngle, 0, 0)
end
return IK
Even if you can give me the smallest hand, I’ll be grateful with it, thank you and have a nice day