Hello! I have had an issue with CFrames on the camera and I can’t seem to be able to solve it. The problem is that I try to set the CFrame Rotation Z to 0 but it doesn’t seem to be working
This is the script
rs.RenderStepped:Connect(function()
local adderx = -((mouse.Y)-mouse.ViewSizeY/2)*sensitivity
--print(-adderx)
newx+=adderx
local completex = math.rad(newx+att.WorldOrientation.X)
local addery = -((mouse.X)-mouse.ViewSizeX/2)*sensitivity
--print(-adderx)
newy+=addery
local completey = math.rad(newy)
--print(xoffset)
--cam.CFrame = CFrame.new(att.WorldPosition) * CFrame.Angles(att.WorldCFrame.Rotation.X, att.WorldCFrame.Rotation.Y, 0)
cam.CoordinateFrame = CFrame.new(att.WorldPosition)
--cam.CFrame = att.WorldCFrame
--prevx += xoffset'
--print(newx)
if newx > nmaxangle then
newx = nmaxangle
print("Oops! too high")
elseif newx < nminangle then
newx = nminangle
print("Oops! too low")
end
--newx=newx*math.abs(att.WorldOrientation.X)
if not char.Humanoid.Sit and not char.HumanoidRootPart.Anchored then
char.HumanoidRootPart.CFrame *= CFrame.Angles(0, cam.CFrame.Rotation.Y, 0)
end
--completex *= math.abs(cam.CFrame.XVector.Unit.Z-1)
--print(cam.CFrame.LookVector.Y)
cam.CFrame *= CFrame.Angles(completex, completey, math.rad(0)) -- OVER HERE
print(completex, " we will catch you next time ")
--print(completex)
--* CFrame.Angles(xoffset, 0, 0)
if adderx > maxcamspeed then
adderx = maxcamspeed
elseif adderx < mincamspeed then
adderx = mincamspeed
end
wait(1/60)
end)
The script is a LOCALscript and it is located in StarterGui
There are values that were assigned outside of the script I’ve provided.
I have indicated where the issue lies. I hope someone can help me!
So this is a first person script that im trying to make. Im making a DOORS fangame. I have another script but it is starting to get old and I really need a new and improved script.
rs:BindToRenderStep("action", Enum.RenderPriority.Camera - 1, function()
local adderx = -((mouse.Y)-mouse.ViewSizeY/2)*sensitivity
--print(-adderx)
newx+=adderx
local completex = math.rad(newx+att.WorldOrientation.X)
local addery = -((mouse.X)-mouse.ViewSizeX/2)*sensitivity
--print(-adderx)
newy+=addery
local completey = math.rad(newy)
--print(xoffset)
--cam.CFrame = CFrame.new(att.WorldPosition) * CFrame.Angles(att.WorldCFrame.Rotation.X, att.WorldCFrame.Rotation.Y, 0)
cam.CoordinateFrame = CFrame.new(att.WorldPosition)
--cam.CFrame = att.WorldCFrame
--prevx += xoffset'
--print(newx)
if newx > nmaxangle then
newx = nmaxangle
print("Oops! too high")
elseif newx < nminangle then
newx = nminangle
print("Oops! too low")
end
--newx=newx*math.abs(att.WorldOrientation.X)
if not char.Humanoid.Sit and not char.HumanoidRootPart.Anchored then
char.HumanoidRootPart.CFrame *= CFrame.Angles(0, cam.CFrame.Rotation.Y, 0)
end
--completex *= math.abs(cam.CFrame.XVector.Unit.Z-1)
--print(cam.CFrame.LookVector.Y)
cam.CFrame *= CFrame.Angles(completex, completey, math.rad(0)) -- OVER HERE
print(completex, " we will catch you next time ")
--print(completex)
--* CFrame.Angles(xoffset, 0, 0)
if adderx > maxcamspeed then
adderx = maxcamspeed
elseif adderx < mincamspeed then
adderx = mincamspeed
end
wait(1/60)
end)
I think I’ll send the code I have been editing in the meantime…
rs:BindToRenderStep("CamWork", Enum.RenderPriority.Camera.Value - 1, function()
--uis.MouseBehavior = Enum.MouseBehavior.Default
--print(xoffset)
--cam.CFrame = CFrame.new(att.WorldPosition) * CFrame.Angles(att.WorldCFrame.Rotation.X, att.WorldCFrame.Rotation.Y, 0)
--cam.CFrame = att.WorldCFrame
--prevx += xoffset'
--print(newx)
local targetcframe = cam.CFrame
local xtarg,ytarg = targetcframe:ToEulerAnglesYXZ()
if newx > nmaxangle then
newx = nmaxangle
print("Oops! too high")
elseif newx < nminangle then
newx = nminangle
print("Oops! too low")
end
--newx=newx*math.abs(att.WorldOrientation.X)
if not char.Humanoid.Sit and not char.HumanoidRootPart.Anchored and not char.Humanoid.PlatformStand then
cameramodule.rotateroot(char, cam.CFrame.Rotation.Y)
--char.Orientation = Vector3.new(0, cam.CFrame.Rotation.Y, 0)
print("updatedChar")
char.HumanoidRootPart.Transparency = 0
char.HumanoidRootPart.LocalTransparencyModifier = 0
end
--completex *= math.abs(cam.CFrame.XVector.Unit.Z-1)
--print(cam.CFrame.LookVector.Y)
local adderx = -((mouse.Y)-mouse.ViewSizeY/2)*sensitivity
--print(-adderx)
newx+=adderx
local completex = math.rad(newx+att.WorldOrientation.X)
local addery = -((mouse.X)-mouse.ViewSizeX/2)*sensitivity
--print(-adderx)
newy+=addery
local completey = math.rad(newy)
--print(-adderx)
--newz
local completez = math.rad(newz+att.WorldOrientation.Z)
cam.CFrame = CFrame.new(att.WorldPosition) * CFrame.Angles(completex, completey, math.rad(0)) -- Over here still
print(completex, " we will catch you next time ")
--print(completex)
--* CFrame.Angles(xoffset, 0, 0)
if adderx > maxcamspeed then
adderx = maxcamspeed
elseif adderx < mincamspeed then
adderx = mincamspeed
end
--wait(1/60)
end)