So the out come that I want is the rotation Y axis of the object/character constant not following the rotation of X axis.
charView.MouseMoved:Connect(function(X, Y)
if holdInDisplay == false then return end
if currentX then
clonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0, math.rad((X-currentX) * 0.5), 0)
end
if currentY then
clonedChar.PrimaryPart.CFrame = clonedChar.PrimaryPart.CFrame:ToWorldSpace(CFrame.Angles(-math.rad((Y-currentY) * 0.5), 0, 0))
end
currentX = X
currentY = Y
end)
So I just got back and tried using A camera and nothing happened camera didn’t change anything.
I tried changing the pivot orientation, and just got an error message saying that Rotation cannot be assigned to and check the wiki saying that it’s not notreplicated, meaning that it’s not scriptable.
I’m not really sure what to change here. I want the Y axis to be constant not following the direction of the X axis. I tired using ToWorldSpace since that looks the right answer but it’s still following the X axis.
Store the Y and X angles separately, then set the CFrame directly every time X and Y changes instead of doing it relative to the current. Also do what @Y_VRN said and apply Y before X:
local pitch = 0
local yaw = 0
charView.MouseMoved:Connect(function(X, Y)
if holdInDisplay == false then return end
yaw += math.rad(X-currentX) * 0.5
pitch += math.rad(Y-currentY) * 0.5
currentX = X
currentY = Y
local root = clonedChar.PrimaryPart.CFrame
root.CFrame = CFrame.Angles(0, yaw, 0) * CFrame.new(pitch, 0, 0) + root.Position
end)
So I manage to get it working, but there is a new problem. The problem is if the camera is behind the character and I move the mouse up and down it goes down and up. Is there like a dot product on roblox check if the camera is behind the character?
charView.MouseMoved:Connect(function(X, Y)
if holdInDisplay == false then return end
if currentX or currentY then
camera.CFrame = (camera.CFrame.Rotation * CFrame.Angles(0, -(X-currentX) * 0.01, 0)) * CFrame.new(0, 0, 6.5)
clonedChar.PrimaryPart.CFrame *= CFrame.Angles(-(Y-currentY) * 0.01, 0, 0)
end
currentX = X
currentY = Y
end)
Nvm just changing the lines worked. All I need now is to clamp the Y axis to -45, 45.
charView.MouseMoved:Connect(function(X, Y)
if holdInDisplay == false then return end
if currentX or currentY then
camera.CFrame = (camera.CFrame.Rotation * CFrame.Angles(-(Y-currentY) * 0.01, 0, 0)) * CFrame.new(0, 0, 6.5)
clonedChar.PrimaryPart.CFrame *= CFrame.Angles(0, (X-currentX) * 0.01, 0)
end
currentX = X
currentY = Y
end)