You can write your topic however you want, but you need to answer these questions:
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.
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.
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
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.
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?
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))
local rotationY = math.rad(-mouseX)
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()
cameraRootPart.Position = head.Position
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.