I want to achieve a camera that can only move on its X axis when I point my mouse in said direction. Such as FNAF’s camera.
(Sorry for no sound, not sure why it didn’t record it)
(Sorry for no sound, not sure why it didn’t record it)
Something like this?
local RunService = game:GetService('RunService')
local UIS = game:GetService('UserInputService')
local Camera = workspace.CurrentCamera
local Size = Camera.ViewportSize
local Center = Size / 2
RunService.RenderStepped:Connect(function()
local Percent = (UIS:GetMouseLocation() - Center) / Size * 2
Percent = Vector2.new(math.clamp(Percent.X,-1,1),math.clamp(Percent.Y,-1,1))
local Angle = CFrame.Angles(0,math.rad(Percent.X * -90),0)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(0,15,0) * Angle
end)
This is good, but I need to also make the camera spawn to a specific part. I’m sorry for the request but I’m not good with this.
Camera.CFrame = CFrame.new(0,15,0) * Angle
Can’t you just change this line so it set’s it to the part’s cframe multiplied by the angle?
Edit : Just make sure it’s facing the right way.