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

Why doesn't my camera focus toward a part I've set as the target?

Asked by
AmiracIe 175
9 years ago

Essentially, I want a camera to be at a part named 'point' that is fixed, meaning that the player cannot move it around using right-click, and also having the camera at 'point' facing another part called 'target'.

My current code is as follows:

local cam=workspace.CurrentCamera
local point=game.Workspace.point

cam.CameraSubject=game.Workspace.point
cam.CameraType="Scriptable"
cam.Focus=CFrame.new(game.Workspace.target.Position)
cam.CoordinateFrame=CFrame.new(point.Position)

Currently, the camera is facing the wrong direction of the 'target' part, which I've set as the focus. Consult with this picture just in case you don't understand: http://i.imgur.com/cAuWsDg.png

The camera should face towards the light that you can kind of see on the left side of the picture, not towards the wall. There is nothing out of the ordinary in the output.

Why doesn't my camera focus towards the part I've set as the target? Everything else seems to be working fine.

2 answers

Log in to vote
11
Answered by 9 years ago
Edited 7 years ago

The CoordinateFrame property of the camera sets all (Without using the Focus and CameraSubject) you need, the origin and the target. CFrame is a combination of position and rotation. All you need is to use one of it's constructors:

CFrame.new(workspace.Part.Position, workspace.Target.Position)

This will make a CFramewith a position on Part and a lookVector (Or simply target) to Target

CFrame.new(Vector3 position, Vector3 point) : Creates CFrame from position, and looking at point. source: wiki.roblox.com

Now you're ready to see!

Ad
Log in to vote
0
Answered by 9 years ago

Some of these are not needed. You can just use the code as follows.

Make sure this is in a Local Script!

local cam = workspace.CurrentCamera
local point = game.Workspace.point

cam.CameraType = "Scriptable"
cam.CoordinateFrame = point.CFrame

If this worked then just accept it as an answer!

Answer this question