How could I merge CFrame and Orientation?

Im making a head rotation with lerp for smoothness for my skinned rig,
but I encountered a problem i’ve been trying to fix for ages.
Because, I can’t merge the two together. I’ve tried converting the orientation to cframe.angles, cframe.fromorientation, or tried making a preview bone. But all possible solutions resulted in weird bugs or weird rotation.

Is there a possible way to merge these two?

bone.WorldCFrame = CFrame.new(bone.WorldCFrame.Position, (pos * CFrame.new(0,0, -9e9)).Position)
local X_C, Y_C, Z_C = math.clamp(bone.Orientation.X, -20, 20), math.clamp(bone.Orientation.Y, -50, 50), math.clamp(bone.Orientation.Z, -20, 20)

--Vector3.new(bone.Orientation.X, bone.Orientation.Y, bone.Orientation.Z)
bone.Orientation = Vector3.new(X_C, Y_C, Z_C)

If I an understanding what you are asking correctly, you can just do something along the lines of:

bone.WorldCFrame = CFrame.new(bone.WorldCFrame.Position, (pos * CFrame.new(0,0, -9e9)).Position)) * 
	CFrame.Angles(
		math.rad(math.clamp(bone.Orientation.X, -20, 20)), 
		math.rad(math.clamp(bone.Orientation.Y, -50, 50)),
		math.rad(math.clamp(bone.Orientation.Z, -20, 20))
	)

Might want to organize it a bit differently though. The initial CFrame.new, takes in a position and a lookatposition, which means its orienting itself to begin with. Then we are changing the orientation and clamping it, which could be the reason its returning weird values.

1 Like