Point a moter6D to a point

I want the Moter6d called Head in my starter character to point towards a point, while having it stay on the players Torso.

Right now i have

player.Character.Torso.Head.C1 = CFrame.new(player.Character.Head.Position, mouseLocation)

and i get
image
How do i do this…

In order to rotate a Motor6D joint you have to manipulate either the C0 or C1 property. These are CFrame objects, but they are relative CFrames so positions would have be relative as well. In your example “mouseLocation” is in world space so that position needs to convert to object space.

I believe you can do:

local relativeMouseLocation = player.Character.Torso.Head.C1:PointToObjectSpace(mouseLocation)
player.Character.Torso.Head.C1 = CFrame.new(player.Character.Head.Position, relativeMouseLocation)

This is not tested… but you should get the idea. You need to convert the world location to a relative location or offset. CFrames | Roblox Creator Documentation

1 Like

Yeah some relativity needs to be done, usually it’s relative to the Part1 CFrame if it’s the C1 property.

But that’s the confusing part, it’s relative to Part1 and the preset C1 or Part0 and C0 used to position the Motor6D in the correct place (depends on which C0 and C1 you are changing). This has caused many troubles especially for a custom rig like @drjellyiam is using.

Consequently, here is a formula for converting a world CFrame into the C0. Derivation of the formula was done from the weld formula here, the only difference is that instead of adding a CFrame rotation to the Part1, it’s been inversed in order to replace it with the worldCFrame instead. Also it can be further optimized if the C1 CFrame is constant no need to access it every function call.

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

local goalWorldSpaceRotationCFrame = CFrame.new(player.Character.Head.Position, mouseLocation)
local headMotor = player.Character.Torso.Head
headMotor.C0 = worldCFrameRotationToC0ObjectSpace(headMotor, goalWorldSpaceRotationCFrame)