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

Trying to lock a camera to a certain spot at a certain view but not working?

Asked by
Troidit 253 Moderation Voter
8 years ago

Alright, I am JUST delving into the art of camera positioning.

I have looked at the regular Roblox forums and the wiki but I can't really find suitable help.

Here's my line of code:

local cam = workspace.CurrentCamera

cam.CameraSubject = game.Workspace.CameraPoint -- CameraPoint is a part 
cam.CameraType = "Attach"

cam.CoordinateFrame=CFrame.new(-331.06, 9.56, 90.161)
cam.Focus=CFrame.new(-331.86, 8.96, 90.961)

The user is spawned elsewhere, but the camera is here instead.

Just to help specify better what the CFrame and Focus thing are doing: http://prntscr.com/85hz9y

SO FAR it's only changed the camera view to attach and MAYBE at first set the focus towards the intended spot.

THE CODE IS put in a local script in the Starter Pack

2 answers

Log in to vote
3
Answered by 8 years ago

OkOkOkOk, here's how you fix it.

You don't.

Shocking, right? I know. Very. Terrifying, actually. How do we fix this!?!? I'm confused! Nononononono. We will use a useful thing called Interpolation. Interpolation for cameras Is. The. Cheese. Basically, what it is is a function that interpolates the camera from its position to another. in a given amount of time. Wait a second.. these are familiar. Oh yes, they are the parameters.

EndPos Is the CFrame where it will end at
EndFocus Is the CFrame it will end looking at.
Duration is the time it will take.

Now that we have these, let's Interpolate this camera.

game.Workspace.CurrentCamera:Interpolate(EndPos, EndFocus, Duration)

BUT, these will have to run at certain conditions.

  • It must be a localscript.
  • The cameratype must be Scriptable

I guess that's it...

So, with this information, we can interpolate the camera to the directions you have supplied.

local cam = workspace.CurrentCamera

cam.CameraSubject = game.Workspace.CameraPoint -- CameraPoint is a part 
cam.CameraType = Enum.CameraType.Scriptable -- always use Enums

local CoordinateFrame=CFrame.new(-331.06, 9.56, 90.161)
local Focus=CFrame.new(-331.86, 8.96, 90.961)

cam:Interpolate(CoordinateFrame, Focus, .1)

And voila, here you go, good sur!

HungryJaffer, Written with StackEdit.

0
Thanks a lot, compared to a lot of other answers I get from other questions I ask, you're the best at EXPLAINING why I should do this or that. Troidit 253 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

You should set the camera mode before you change the rest of the camera's settings.

local cam = workspace.CurrentCamera

cam.CameraType = "Attach" 
cam.CameraSubject = game.Workspace.CameraPoint 

Answer this question