Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 9 years ago

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) 
0
That is something I always wanted to do, good question. Tesouro 407 — 9y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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
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. Orlando777 315 — 9y
Ad

Answer this question