How to make the camera follow the player in the same relative position it was upon firing?

Greetings,

I am trying to have the camera follow the player at the same relative position as it was when i turned it into scriptible.

So if player’s position is i.e. Vector3.new(0,2,0) and the camera’s position is Vector3.new(0,4,-10)

i want to keep this distantance and orientation between them but still have the camera follow the torso so that when

the player’s position is Vector3.new(0, 2, -14) the camera’s position is Vector3.new(0, 4, -24)

unfortunately i suck at math and i can’t work this out for the life of me, here is what i have so far

camera.CameraType = Enum.CameraType.Scriptable

  Stepped = game:GetService("RunService").RenderStepped:Connect(function()
  	local HRP = Player.Character.HumanoidRootPart
  	local oldC = camera.CFrame

  	camera.CFrame = HRP.CFrame * CFrame.new(0,4,12)

end)

the best i’ve been able to do is get the camera to follow at a relative position that i manually set, but this isn’t what i want

Thank you for your time

1 Like

You can save an offset between CFrames using CFrame:Inverse:

local HRP = Player.Character.HumanoidRootPart
local oldC = camera.CFrame
local cameraOffset = HRP.CFrame:Inverse() * oldC -- new code

camera.CameraType = Enum.CameraType.Scriptable
Stepped = game:GetService("RunService").RenderStepped:Connect(function()
	camera.CFrame = HRP.CFrame * cameraOffset
end)

I wrote a reply on what CFrame:Inverse does, if you want to check that out:

4 Likes

Thank you very much. Not only have you solved my issue, you’ve also taught me something new.
Sadly upon getting what i wanted i realized that it was a bad idea xD. Depending on where the camera is relative to the player upon firing it makes the movement clunky at best and impossible at the worst xD

I thank you all the same tho, my quest for a radial menu continues

2 Likes

Bro add all the variables at least (Necro bump sorry)