How can I rotate the camera when its attached to a Part in the workspace

I figured out the issue. Instead of the code being part.CFrame = part.CFrame * CFrame.fromEuler..., it should start with cam.CFrame. This is because you defined cam as the character’s built-in camera. For the line above the one I mentioned, it says cam.CFrame = CFrame.new(part.Position). This is fine. But, in the original script, the next line was part.CFrame = .... You already started modifying cam, so you should say cam.CFrame from now on, not Part.CFrame.

I am unable to give you the precise angles. You’ll need to play around with it. This is because I’m not aware how the cylindrical part is actually placed. If you edit the values after the .fromEulerAngelsXYZ, the camera should be moving. Just keep editing the values until you want it how you want it.

Yeah I had figured that out when i took the first look at the code, but I just realized that it was a cylindrical part… Do you think it will have any effect if I switch it back to a normal part?

If you add a regular part, you need to make sure the front of the part is facing the build.


The highlighted side on the part is on the front and is facing the map.

Then, in your code, instead of having cam.CFrame = CFrame.new(part.Position), you should have cam.CFrame = part.CFrame.

You should remove the .fromEulerAnglesXYZ line of code from your script. The last line should be the one I mentioned above.

Hope that boosts you to your goal! :+1:

2 Likes

Just another approach to play around with.

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

-- lookat point offsets for camera
-- The position of a camera is conveniently in line with the
-- center of its viewport. Creating a lookat point horizontal
-- to the position of the camera can be used to point the camera
-- without introducing tilt or roll
local dir = {
	["X"] 	= Vector3.new(1, 0, 0),		-- yellow part
	["-X"] 	= Vector3.new(-1, 0, 0),	-- red part
	["Z"] 	= Vector3.new(0, 0, 1),		-- blue part
	["-Z"] 	= Vector3.new(0, 0, -1)		-- green part
}

local camPosition = Vector3.new(0,10,0)   	-- camera location
local dirChoice = "X" 						-- start direction
local lookat = dir[dirChoice]				-- get the Vect3 for choice

-- use the [CFrame.new(position, lookat_point)](http://wiki.roblox.com/index.php?title=CFrame#CFrame.new) constructor of CFrame
camera.CFrame = CFrame.new(camPosition, camPosition+lookat)

-- some code to cycle through the directions
while true do
	for _, lookoffset in pairs(dir) do
		camera.CFrame = CFrame.new(camPosition, camPosition+lookoffset)
		wait(1)
	end
	wait()
end

Of course the cam position in my example can be replaced with the pos of another part in the workspace. The lookat could be applied to the part and then used for the camera by just assigning the camera cframe to that of the part. Or, you could just use the position of your part and let another lookout point handle the orientation. Lots of options.

Anyway, that lookat approach is handy if you end up doing camera paths at some point and need to keep the camera looking at something specific. Best of luck.

1 Like

Thank you to everyone that has helped me!

1 Like