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

LookVector on CFrame not working on viewport frame?

Asked by
kepiblop 124
4 years ago

Hello I am trying to do a viewport frame script. The problem is when i'm using a CFrame for a camera for the viewport frame this happens

14:28:09.213 - game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector:1: invalid argument #3 (CFrame expected, got Vector3) 14:28:09.215 - Stack Begin 14:28:09.225 - Script 'game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector', Line 1 14:28:09.227 - Stack End

What I want to achieve is there is a part above the viewport frame that the camera will face In front of. Now I actually do know that look vector is meant for vector3 but is there a way to use it in a CFrame? Here is the code

game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5
game.StarterGui.SurfaceGui.ViewportFrame.CurrentCamera = game.Workspace.Viewportcam
game.Workspace.Viewportcam.CameraType = Enum.CameraType.Scriptable
game.Workspace.Viewportcam.CameraSubject = game.Workspace.Cam

for i,v in pairs(game.Workspace:GetDescendants()) do
    if v:IsA("BasePart") then
        local vclone = v:Clone()
        vclone.Parent = game.StarterGui.SurfaceGui.ViewportFrame
        game["Run Service"].RenderStepped:Connect(function()
            vclone.CFrame = v.CFrame
        end)
    end
end

For some more info

The local script is in replicated first

Camera is in workspace

Gui is a SurfaceGui (I could use billboard but I want to use surfacegui for this case.)

But in advance thanks!

0
You are using the CFrame incorrectly check out the CFrame Developer article on it https://developer.roblox.com/en-us/api-reference/datatype/CFrame Benbebop 1049 — 4y
0
Wait i think i realized do i have to add the look vector to the cframe? kepiblop 124 — 4y
0
"game.Workspace.Cam.CFrame.LookVector * 5" What were you trying to do User#30567 0 — 4y

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

In your script as follows:

game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5
game.StarterGui.SurfaceGui.ViewportFrame.CurrentCamera = game.Workspace.Viewportcam
game.Workspace.Viewportcam.CameraType = Enum.CameraType.Scriptable
game.Workspace.Viewportcam.CameraSubject = game.Workspace.Cam

for i,v in pairs(game.Workspace:GetDescendants()) do
    if v:IsA("BasePart") then
        local vclone = v:Clone()
        vclone.Parent = game.StarterGui.SurfaceGui.ViewportFrame
        game["Run Service"].RenderStepped:Connect(function()
            vclone.CFrame = v.CFrame
        end)
    end
end

i would change the 1st line from game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5

To

game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame * CFrame.new(game.Workspace.Cam.CFrame.LookVector * 5)

as you was converting the Cframe of the camera part to a Vector3 so i've modified the line so it puts the camera 5 studs away from your camera brick according to its LookVector

As for the rest of your script, it looks good!

Hope this helps!

0
Oh so basically you multiply the CFrame with the Lookvector by 5? Well now i learnt something new! I will try this out.. kepiblop 124 — 4y
0
Well apparently no errors but it didn't work because its only a test but I actually got informtion on using look vector on CFrame! I will mark this as a solution because that was the main point. kepiblop 124 — 4y
Ad

Answer this question