Camera Tweening

Hello. I’m trying to recreate the camera in the game Foxhole (If you haven’t heard of it search it up, it’s pretty cool). Anyways I’m trying to create the function to rotate the camera. All my current tries of adding CFrame.Angles(0,math.deg(45),0) to the new CFrame coordinate just makes the camera glitch. Anything to help would be appreciated.

My code


local Plr = game.Players.LocalPlayer
repeat wait()
until Plr.Character:FindFirstChild('Head')
local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraType = Enum.CameraType.Scriptable


local TS = game:GetService("TweenService")
local RS = game:GetService('RunService')

local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0, false, 0)
local Head = Plr.Character:WaitForChild("Head")

while true do
	local Rotation = script.Rotation.Value
	local Distance  = script.Distance.Value
	local tween = TS:Create(Camera, tweenInfo, {CoordinateFrame = CFrame.new(Vector3.new(Head.Position.X - script.TopDownValue.Value, Head.Position.Y + Distance, Head.Position.Z + Rotation), Vector3.new(Head.Position.X + 10, Head.Position.Y, Head.Position.Z))})
	tween:Play()
	RS.Stepped:Wait()
end

Video of what the code does:

Tl;dr
How do I make it possible to rotate the camera so it’s facing a new direction? Either using UserInputService or the head LookVector. Looking for specific help for the rotation.

Thanks in advance

7 Likes

First thing, don’t use Camera.CoordinateFrame as it’s deprecated, use CFrame instead. Another thing, you’re creating a new frame every time .Stepped runs. Not sure if you’re trying to play a tween infinitely or if you’re trying to manipulate the camera’s CFrame on each .Stepped event but you should choose one or the other.

Now, there are a few ways to approach this:

1- Create a new CFrame on .Stepped
2- Modify the camera’s CFrame applying an offset every time.

Option 1:
This creates a new CFrame with the positional data of the camera’s CFrame

local tween = tweenService:Create(Camera, tweenInfo, {CFrame = CFrame.new(Camera.CFrame.p) * CFrame.Angles(0,math.rad(45),0)})
tween:Play()
tween.Completed:Wait()

Option 2:
This takes the camera’s CFrame and applies a 45 degree offset to the Y axis.

local tween = tweenService:Create(Camera, tweenInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(45),0)})
tween:Play()
tween.Completed:Wait()
14 Likes