Problem with joint rotation issues

Hello everybody, I’ve been having a problem with a camera script I’ve been coding.

Background

So, I’ve made a fork of a camera system by @TTVkreisikinuski and I’ve started to recode it to work differently. I want it to now change the rotation of the head instead of the camera then have the camera’s Cframe be the head’s Cframe.

The issue is that the head rotates in goofy ways

Sorry about there being no video, OBS was acting up

I’ve thought of a solution by using the math.cos() and math.sin() of the Z rotation of the joints C1. But I don’t know how to get the individual x,y,z rotations of the joint.

Here is the whole of my code so far

--Sevices--
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")

--Const--
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Human = Char:WaitForChild("Humanoid")
local IsR6 = (Human.RigType.Value==0)
local Root = Char:WaitForChild("HumanoidRootPart")
local Head = Char:WaitForChild("Head")
local Torso = (IsR6 and Char:WaitForChild("Torso")) or Char:WaitForChild("UpperTorso")
local Neck = (IsR6 and Torso:WaitForChild("Neck")) or Head:WaitForChild("Neck")
local RootC = (IsR6 and Root:WaitForChild("RootJoint")) or Char:WaitForChild("LowerTorso"):WaitForChild("Root")

--Vars--
local CamXRot = 0
local CamYRot = 0

--Var/Const Setup--
Neck.MaxVelocity = 1/3

--Functions--
function Lerp(a,b,t)
	return a*(1-t)+b*t
end

function UpdateCamera()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	CamXRot *= 0.6
	CamYRot *= 0.6
	Neck.C1 *= CFrame.Angles(0,0,math.rad(CamXRot*-2))
		* CFrame.Angles(math.rad(CamYRot*2)*math.cos(Neck.C1.Rotation.Z),math.rad(CamYRot*2)*math.sin(Neck.C1.Rotation.Z),0)
	--print(Neck.C1.Rotation)
	--[[
	if math.abs(Neck.C1.Rotation.Z - RootC.C1.Rotation.Z) > 60 then
		RootC.C1 *= CFrame.Angles(0,math.rad(CamXRot*-2),0)
	end
	]]--
	--[[Head.CFrame *= CFrame.Angles(0,math.rad(CamXRot*2),0)
		* CFrame.Angles(math.rad(CamYRot*2),0,0)
		]]--
end

function MoveCamera(name: string, state: EnumItem, input:InputObject)
	if state == Enum.UserInputState.Change then
		--print(input.Delta.X)
		CamXRot += input.Delta.X*-0.08
		CamYRot += input.Delta.Y*-0.08
		--[[Torso.CFrame.Orientation *= CFrame.Angles(0,math.rad(-CamXRot),0)
			* CFrame.Angles(math.rad(-CamYRot),0,0)
			]]--
		--[[if Head.CFrame.Orientation.X > 70 then
			CamYRot *= 0.4
		end
		]]--
	end
end

function Start()
	print("Start")
	ContextActionService:BindAction("MoveCamera", MoveCamera, false, Enum.UserInputType.MouseMovement)
	--ContextActionService:BindAction("ScrollCamera", ScrollCamera, false, Enum.UserInputType.MouseWheel)
	RunService:BindToRenderStep("CameraSystem", Enum.RenderPriority.Camera.Value, UpdateCamera)
	Char:WaitForChild("Humanoid").AutoRotate = false
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end

Start()

Player.CharacterAdded:Connect(function(character: Model)
	Char = character
	Start() --// Fixes bug where it wouldn't work after death
end)

if you have any solution, please tell me

nvm, found out i can use some trig and CFrame:VectorToObjectSpace() to find out the rotations.

here is the actual solution to help people:

local TempOrientation = Neck.C1:VectorToObjectSpace(Vector3.new(1, 0, 0))
local NeckOrientation = Vector3.new(math.deg(math.atan2(TempOrientation.Y, TempOrientation.X)), math.deg(math.atan2(TempOrientation.Z, TempOrientation.X)), math.deg(math.atan2(TempOrientation.Y, TempOrientation.Z)))```

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.