How do I script my camera to look at my part that I move, kinda like following a bullet came?

How do I script my Camera to look at my part that I’m moving without seeing my character?

example of what im trying to achieve of angle:

the Cyan/Blue part is what I want to be just above, to see where to go and to see the part up close too at the same time.

For this you will probably want to use CFrame.lookAt(pos: Vector3, lookAt: Vector3)
Basically you just need to get the position of the blue part, then to make it sit just above it, add half of the size.Y to the Y position, and a backwards offset, then just put the position of the blue part as the second argument.

-- change the Y component to something else if you want it to be higher up. Z component is how far back it is.
local offset = Vector3.new(0, bluePart.Size.Y / 2, 3)
local partPos = bluePart.Position
cam.CFrame = CFrame.lookAt(partPos + offset, partPos)

Where do I put this script? and what script do I use, LocalScript or Script?

If you are going to be manipulating the camera, it will need to be a LocalScript.
you will need to set the camera.CameraType = Enum.CameraType.Scriptable, and it would probably be easiest to set up a RunServive.RenderStepped loop to update the camera each frame. It’ll look something like this:

local RunService = game:GetService("RunService")

local cam = workspace.CurrentCamera
local bluePart = workspace.BluePart
-- the offset value may need to be modified based on how you are going to be moving the part
local offset = Vector3.new(0, bluePart.Size.Y / 2, 3)
cam.CameraType = Enum.CameraType.Scriptable

RunService.RenderStepped:Connect(function()
	local partPos = bluePart.Position
	cam.CFrame = CFrame.lookAt(partPos + offset, partPos)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.