How would I offset the camera with rotation?

You shouldn’t use a direct offset then, maybe you should store an offset and apply it to the camera. as a cframe is basically a mathematical matrix.

and then you can always edit that stored offset.
for that, I’ll try to come up with something for you real quick

Alright so here is a quick prototype that works

local oldOffset = CFrame.new() -- Don't edit this!
local offset = CFrame.new()

-- (Optional): Will accumulate the time in seconds since the script started
local t = 0

game:GetService("RunService").RenderStepped:Connect(function(delta)
	-- (Optional): Accumulate the time in seconds
	t += delta
	-- Cancel out the offset we applied in the previous frame
	cam.CFrame *= oldOffset:Inverse()
	-- Apply the new offset
	cam.CFrame *= offset
	-- Store the offset we have applied so we cancel it in the next frame
	oldOffset = offset
	-- Update the offset that will applied!
	offset = CFrame.Angles(math.sin(t), 0, 0)  --You can change this however you want!
	-- Proof (Optional): You can update the original cframe without affecting the offset
	cam.CFrame *= CFrame.new(math.sin(t)*10, 0, 0) --You can change this however you want!
end)

This gives you a relative cframe that you can play with without overriding the original camera cframe.
If you’re interested, I can make it as a robust function for you!

6 Likes

Thank you so much and no, it’s alright.

1 Like

EDIT: Added comments to help you understand the code!

2 Likes

Saved me hours of custom camera scripting. Thank you, g!

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