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

How could I get a part to have the same vertical rotation as the camera?

Asked by 9 years ago

I want a block to have the same vertical rotation as the camera. The problem is, vertical rotation isn't straightforward.

Example: If the camera faces north, it is zero. If it faces east, it is 360(camera rotations are actually in radians but that doesn't matter too much) If it faces south, again it is zero. if it's facing west, it's -360.

Applying the direct CFrame wouldn't work since the part would have to flip over. How could I have the part have the same vertical rotation?

My current script (the part act's really weirdly):

wait(1)--ignore this
while true do
    local rot = workspace.CurrentCamera.CoordinateFrame.lookVector.X
    if rot < 0 then
        rot = -rot * 2
    end
    script.Parent.BodyGyro.CFrame = CFrame.Angles(0,rot*360,0)
    print(workspace.CurrentCamera.CoordinateFrame.lookVector * 360)--ignore this too
    wait(0.1)
end

Answer this question