# Can't combine CFrames

You can write your topic however you want, but you need to answer these questions:

1. What do you want to achieve? Keep it simple and clear!
I wan’t to combine mouse X axis with Y mouse axis for my 3rd person character controller.
2. What is the issue? Include screenshots / videos if possible!
I really suck at CFrame and I don’t understand a thing so I hope this would be easy for an advanced scripter.
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried all sorts of things to try to put them together so I got so desperate and asked ChatGPT
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

If you wan’t, I can record videos of what these components do

``````-- --// MOUSE X AXIS
local orientation = CFrame.new(rootPart.Position, rootPart.Position + Vector3.new(lookVector.X, 0, lookVector.Z))
cameraRootPart.CFrame = orientation * CFrame.Angles(0, math.rad(-mouseX), 0)
rootPart.CFrame = orientation * CFrame.Angles(0, rotationY, 0)

--// MOUSE Y AXIS
local orientation = CFrame.new(rootPart.Position, rootPart.Position + Vector3.new(0, lookVector.Y, lookVector.Z))
local rotationX = math.asin(orientation.lookVector.Unit.y) - math.rad(-mouseY)
rotationX = math.clamp(rotationX, -MIN_Y*math.pi/180, MAX_Y*math.pi/180)
cameraRootPart.CFrame = CFrame.new(cameraRootPart.Position) * orientation:toObjectSpace(CFrame.new(cameraRootPart.Position, cameraRootPart.Position + lookVector)) * CFrame.Angles(rotationX, 0, 0)
``````

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Could you draw a picture or elaborate, because it’s really how to figure out from your code. How would this be practical or what are you trying to use it for?

1 Like

I’m sorry, I wan’t to send a video but what site can I use to share it as a link?

1 Like

Have you ever heard of gyazo? Try using it, i’ve never but I commonly see people use it.

1 Like

here is X axis
https://i.gyazo.com/2299d8849f922057e75a68b7b19bc013.mp4

1 Like

So you want the player to follow the mouse?

1 Like

no, the player doesn’t follow the mouse, instead based on my own calculations I rotate the player based on MouseX aka delta.X

Here is what happens when I move my mouse on the Y axis:
https://gyazo.com/45212b01f3cb0affb504bf749440f123

I wan’t it to look like this:
https://gyazo.com/7046e2d272fe1bdb07130ec3d4562730

here is my script:

``````local function rotateBody(actionName, inputState, inputObject)
local delta = inputObject.Delta

local mouseX = delta.X
local mouseY = delta.Y

if math.abs(mouseX) > math.abs(mouseY) then
if mouseX > 0 then
--print("moving Right!")
else
--print("moving Left!")
end
else
if mouseY > 0 then
--print("moving down!")
else
--print("moving up!")
end
end

local lookVector = camera.CFrame.lookVector

--// MOUSE X AXIS
local orientation = CFrame.new(rootPart.Position, rootPart.Position + Vector3.new(lookVector.X, 0, lookVector.Z))
cameraRootPart.CFrame = orientation * CFrame.Angles(0, math.rad(-mouseX), 0)
rootPart.CFrame = orientation * CFrame.Angles(0, rotationY, 0)

--// MOUSE Y AXIS
local orientation = CFrame.new(rootPart.Position, rootPart.Position + Vector3.new(0, lookVector.Y, lookVector.Z))
local rotationX = math.asin(orientation.lookVector.Unit.y) - math.rad(-mouseY)
rotationX = math.clamp(rotationX, -MIN_Y*math.pi/180, MAX_Y*math.pi/180)
cameraRootPart.CFrame = CFrame.new(cameraRootPart.Position) * orientation:toObjectSpace(CFrame.new(cameraRootPart.Position, cameraRootPart.Position + lookVector)) * CFrame.Angles(rotationX, 0, 0)

end

local function moveCamera()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

camera.CFrame = cameraRootPart.CFrame * CAMERA_OFFSET
end

game:GetService("ContextActionService"):BindAction("MouseMoved", rotateBody, false, Enum.UserInputType.MouseMovement)
BindAction(actionName, functionToBind, createTouchButton, inputTypes)

RunService.RenderStepped:Connect(moveCamera)
``````

I found that the order I have to do this is

1.Lock curser at center
2.Rotate body when cursor moved
3.Reposition camera to cameraRootPart when cursor has been moved

since I can’t rotate the humanoid root part up and down I created a part “cameraRootPart” at the position of the head that the camera glues to. cameraRootPart take cares of rotation on the X axis.