Hello! So basically I’m trying to make a very specific camera angle depending on where you are in relation to a part. I know that there probably is some kind of math that can get this done, but I personally have no clue. I want the player to always be looking at the part, but with an offset behind them. Here’s a picture showing what I’m talking about:
I already have an offset variable that sets the offset I want to the camera with a Vector3. Here’s the custom camera script (ismonster1 will equal true during this):
`task.wait()
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local campart = game.Workspace.Camera
local maxTilt = 5
local ts = game:GetService("TweenService")
local angle = "front"
previousposition = campart.CFrame
local cando = true
local ismonster1 = false
local CameraShaker = require(game.StarterPlayer.StarterPlayerScripts.CameraShaker)
local anglevalues = {
["right"] = Vector3.new(0,1.5,10),
["left"] = Vector3.new(0,1.5,-10),
["front"] = Vector3.new(-10,1.5,0),
["top"] = Vector3.new(-2,15,0),
["back"] = Vector3.new(10,1.5,0),
["angledfront"] = Vector3.new(-10,7,0),
["birds"] = Vector3.new(-2,25,0)
}
game:GetService("RunService").RenderStepped:Connect(function(deltatime)
local offset = Vector3.new(0,0,0)
local humroot = char:FindFirstChild("HumanoidRootPart")
if cando == true then
local asd = 0
camera.FieldOfView = 72.5
offset = (anglevalues[angle])
local crouchscript = game.Players.LocalPlayer.Character:FindFirstChild("CrouchScript")
if crouchscript ~= nil then
if crouchscript.Crouch.Value == true then
offset = offset - Vector3.new(0,2,0)
end
end
end
local previous100fpsvalues = {}
local fps = 1 / game:GetService("RunService").RenderStepped:wait()
table.insert(previous100fpsvalues,fps)
if #previous100fpsvalues > 100 then
table.remove(previous100fpsvalues,previous100fpsvalues[10])
end
local averagefps = 0
for i,v in ipairs(previous100fpsvalues) do
averagefps = averagefps + v
end
averagefps = averagefps / #previous100fpsvalues
local valuee = 0.08 * (deltatime * (60 + averagefps))
if cando == true then
if humroot ~= nil then
if ismonster1 == false then
local twen = ts:Create(campart, TweenInfo.new(valuee,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut), {CFrame = CFrame.new((humroot.Position + offset), humroot.Position)})
camera.FieldOfView = 70
twen:Play()
else
local twen = ts:Create(campart, TweenInfo.new(valuee,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut), {CFrame = CFrame.new((humroot.Position + (offset + Vector3.new(0,1.5,0))), game.Workspace.CameraLookAt.Position)})
camera.FieldOfView = 105
twen:Play()
end
end --magnitude, roughness, fadeInTime, fadeOutTime, posInfluence, rotInfluence
end
--[[camera.CFrame = campart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 1.5)/mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 1.5)/mouse.ViewSizeX)) * -maxTilt),
0
)]]
end)`
If you need anymore information, reply below (this is a repost)