Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get a local CFrame rotation and apply it to camera roll?

I want the camera to rotate on the parts LOCAL axis. I believe :toEulerAngles is on the global axis though. Here's the problem. When I rotate the brick on the z axis, everything's fine. But as it starts rotating on the Y, the camera seems to change when it shouldn't, because it should only rotate according to the parts local Z axis.

local x,y,z = workspace.Part.CFrame:toEulerAnglesXYZ()
print(y)

roll = y
game.Workspace.CurrentCamera:SetRoll(roll) 

1 comment

0

That is something I always wanted to do, good question.

1 answer

You can do this by simply setting the CoordinateFrame of the Camera to the part's CFrame. the CameraType would have to be Scriptable and the CameraSubject will have to be that part.

local cam = workspace.CurrentCamera
local reference = workspace.Part

cam.CameraType = 'Scriptable'
cam.CameraSubject = reference

while wait() do
	cam.CoordinateFrame = reference.CFrame
end

This would theoretically match every angle of the part with the Camera. But just be sure, let's use the CFrame operator that takes in two arguments, one as the Vector3 origin, and the second as the Vector3 lookat.

local cam = workspace.CurrentCamera
local reference = workspace.Part

cam.CameraType = 'Scriptable'
cam.CameraSubject = reference

while wait() do
	cam.CoordinateFrame = CFrame.new((reference.CFrame * CFrame.new(0,5,5)).p,reference.CFrame.p)
end

1 comment

0

No, thats the problem. When using the method with a Vector3 Look at it will not change the camera roll at all. You have to manually change the camera roll. Only problem is that I can not get the local Angles.

This discussion is preserved as it was. New answers, comments, and votes are closed.