IK welding [Solved]

I am developing a paintball type of game where players will have their arms point towards their gun.

Plan #1
I’ve tried welding the arms to the player’s torso, and then tried having the arms point towards the gun’s position.

Because the torso has rotation involved, using the CFrame(base, target) method to point the player arms towards the gun is always incorrect.

plan #2
However, if the player arms were not welded, I could anchor them, and then update it’s CFrame easily because I don’t have to deal with rotation offsets. However, using this plan, the arms might look glitchy considering that there might be lag or something.

Any ideas?

Note:

while true do
	wait()
	
	part.CFrame = CFrame.new(base.CFrame.p, target.CFrame.p)*CFrame.new(0, 0, -2)
end

image

If you guys know a way to use C0 and C1 weld properties to do the same task as above^, I would highly appreciate it :slight_smile:

Sorry if this topic is a little unclear, it’s similar to inverse kinematics logic, but it’s meant for R6 character arms.

Fixed my code:

local base = workspace.base
local part = workspace.part
local target = workspace.target


local w = Instance.new("Weld")
w.Parent = base
w.Part0 = base
w.Part1 = part


while true do
	wait()
	local cf = CFrame.new(base.CFrame.p, target.CFrame.p) * CFrame.new(0, 0, -1) * CFrame.Angles(0, math.pi, 0) * CFrame.Angles(math.pi / 2, 0, 0)
	w.C0 = base.CFrame:toObjectSpace(cf)
	
end
2 Likes