How can I position a camera to a certain position

I am making a tool where when player click then it positions his camera infront of the tool brick.

To prevent bad angles using a brick to put the camera position to, I want to offset a camera in a certain direction of the brick.

This is my current code with the bricks:

game.Workspace.CurrentCamera.CFrame = CFrame.new(CameraPart.Position, LookPart.Position)

CameraPart is the small brick for the camera and LookPart is the brick which I want it to look at/be positioned off in the future.

3 Likes

I think CurrentCamera should be camera.
vector3 does not go with CFrame

game.Workspace.Camera.Cframe = CameraPart.CFrame
1 Like

I recommend you to use Remote Events

This is the normal script side:

local RemoteEvent = game:GetService(“ReplicatedStorage”).RemoveEvent

part.ClickDetector.MouseClick:Connect(function(plr)
RemoteEvent:FireClient(plr) – Fired the Event
end)

This is the local script side:

local RemoteEvent = game:GetService(“ReplicatedStorage”).RemoveEvent

RemoteEvent.OnClientEvent:Connect(function()
– Type your function here. Whenever one clicks the button this function is going to be working.
end)

2 Likes

I’m already using remote event for this

What issues are you currently having with what you’ve written?

You have to set the cameratype to scriptable, else the default camera scripts override what you set.

So then I don’t need to use a brick to assign position to the camera and rather use the lookat brick

If you want to get the Position infront of a part, you can use CFrame.lookVector to offset 1 stud infront of the part. This would be based on the front face of the part

If you multiply by lookVector by a value, it will move x studs in that direction.

local distanceOutwards = 5
local originPosition = part.Position + (part.CFrame.lookVector * distanceOutwards) -- Gets a position 1 stud infront
local targetPosition = part.Position
Camera.CFrame = CFrame.new(originPosition,targetPosition)

This code would set the camera to be placed infront of the brick, and facing towards the brick, without the need to get multiply bricks

2 Likes