Motor6D CFrame is not correct with Part CFrame

So it was just a problem about a motor6d. When a player stabs a target. The hand should be on a part cframe but it just teleports on some where else. I dont know how to do this! Please help!


b65959a.mp4
Code:

wait()

local torso = script.Parent:WaitForChild("Torso")

local rshoulder = torso:WaitForChild("Right Shoulder")

local direction = (script.Parent.Parent.Target.Head.Position - script.Parent:FindFirstChild("Right Arm").Position).Unit * (script.Parent.Parent.Target.Head.Position - script.Parent:FindFirstChild("Right Arm").Position).Magnitude

local origin = script.Parent:FindFirstChild("Right Arm").Position

local midpoint = origin+direction/2

local lastpos = rshoulder.C0

local part = Instance.new("Part",game.Workspace)

part.Anchored = true

part.CFrame = CFrame.new(midpoint,origin)

rshoulder.C1 = part.CFrame

With Motor6ds you will usually need a special formula, try this one.

local function worldCFrameRotationToC0ObjectSpace(motor6DJoint,worldCFrame)
	local part1CF = motor6DJoint.Part1.CFrame
	local c1Store = motor6DJoint.C1
	local c0Store = motor6DJoint.C0
	local relativeToPart1 =c0Store*c1Store:Inverse()*part1CF:Inverse()*worldCFrame*c1Store

	local goalC0CFrame = relativeToPart1.Rotation+c0Store.Position--New orientation but keep old C0 joint position
	return goalC0CFrame
end

part.CFrame = CFrame.new(midpoint,origin)

rshoulder.C0 = worldCFrameRotationToC0ObjectSpace(rshoulder, part.CFrame)
1 Like

It worked quite. Also the front part rotate to behind instead of it should be on the front and It doesnt spawn on a correct position. Any Idea? I’ll try to figure out the flip prob

Alright, i fixed the rotation problem now but i got no idea how to positioning it. Also I used cframe.Angles to do it for any one who cant figured it out

image
It WORKEDDD!!!
Thanks :heart_eyes: :heart_eyes: :heart_eyes:

1 Like