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

Keeping a camera focused on a brick?

Asked by 9 years ago

I tried the blog, I tried a bit of free models, I even tried my own. But I wanted to make a camera that is only focused on that one brick and I even made it a localscript I honestly dont see how it's not working

1
Post the script you created Discern 1007 — 9y
0
What do you mean by "Focused on a brick"? EzraNehemiah_TF2 3552 — 9y
0
And the camera, is it a player's camera? Please be more elaborate. Shawnyg 4330 — 9y
0
Ya it will be the Player's camera. But I want the camera ON the brick so it's only pointed one way and it's not on your player at all the camera is on the brick. Zolerus 0 — 9y

2 answers

Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
9 years ago

I have already answered this question here.

I emphasize that you must thoroughly search through other questions first because this is very similar.

So I will just copy and paste it:

You want to use Coordinate frame , it has two parameters:

It can set a position for the camera

It can set what the camera is facing

More detailed explaination:

CoordinateFrame:

First of all, CoordinateFrame is the extended name of CFrame. The CoordinateFrame property of the camera is simply the position of the camera.

game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(10,50,30) 
-- Positions camera at 10, 50, 30

Focus:

The Focus property is simply that the camera is looking at. To set the Focus property, you would do it the same was as CoordinateFrame:

game.Workspace.CurrentCamera.Focus = CFrame.new(0,10,0) 
-- Makes the camera look at 0, 10, 0

Setting the Focus will automatically rotate the camera in it's CoordinateFrame position.

Locking the camera:

Sadly, setting these properties does not lock the camera's position. The player can still rotate and move the camera around at their will. Currently there is no efficient way to go about solving this, that I know of. (Can someone second this?)

For now, the only way to lock the camera is to set a continuous loop. Example:

while true do
    game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(10,50,30)
    game.Workspace.CurrentCamera.Focus = CFrame.new(0,10,0)
    wait()
end

For your use: Make the camera:

Player = game.Players.LocalPlayer
Camera = Player.Camera

The CoordinateFrame slightly out from the part

Part = --Part's parenting
Camera.CoordinateFrame = Part.Position + Vector3( 5, -5, 0)

And the Focus, focused on the part:

Camera.Focus = Part.Position

Altogether: (This should work)

Player = game.Players.LocalPlayer
Camera = Player.Camera

Part = --Part's parenting
Camera.CoordinateFrame = Part.Position + Vector3( 5, -5, 0)
Camera.Focus = Part.Position
Ad
Log in to vote
-1
Answered by 9 years ago

I think I may have the answer to your question.

NOTE: In order for this to work. The script must be a LOCALSCRIPT placed inside StarterPack, StarterGui, or anywhere inside a player, or a player's character!

EDIT: I am making a script that changes the camera's subject to a part in Workspace named "Part" when you push F, then puts the focus back onto the player by pushing F again. I will point out which code to use when taking code from this script

local Player = game.Players.LocalPlayer --Get the Player
local mouse = Player:GetMouse() --Get the Player's Mouse
local Focused = false
--To get the camera place this variable at the top of your localscript
local Camera =  game.Workspace.CurrentCamera --WARNING: Try this from a Normal script and the camera can NOT be accessed! Use a LocalScript!

mouse.KeyDown:connect(function(key) --Wait for a key to be pressed
    if key == "f" then --If the key was f then
        if not Focused then --If the camera is NOT focused then
            Focused = true --Focused is now true
            --Place this where you would like to change the camera's subject to the part. BE SURE TO CHANGE 'game.Workspace.Part'!
            Camera.CameraSubject = game.Workspace.Part --Change the subject to game.Workspace.Part
--          Camera.CameraType = "Attach" --If you want the player to be unable to turn the camera left and right Uncomment this line!
        elseif Focused then --If it is focused then
            Focused = false --Make focused false
            --Place this where you would like the camera to go back to it's original view.
            Camera.CameraSubject = Player.Character.Humanoid --Change the camera to it's original view
            Camera.CameraType = "Custom" --Allow the camera to be moved around freely
        end
    end
end)

Did this help? Click the "Accept Answer" button below my character for you and me to receive reputation!

0
Please don't just supply code as an answer. This doesn't help them learn anything. Explain your answer. Goulstem 8144 — 9y
0
Edited. Explained a little more. Sorry if it confused you! lightpower26 399 — 9y

Answer this question