Nogalo
(Nogalo)
November 2, 2020, 6:09am
#1
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:
So first, a solid definition for a CFrame:
A CFrame is something that describes a combined position and angle.
That is literally all it is. All CFrame constructors revolve around creating CFrames with specific properties. e.g. CFrame.new's 3-number constructor creates a CFrame with a position, but no angle, while CFrame.Angles, CFrame.fromOrientation, etc., creates a CFrame specifically with an angle.
You are probably talking about inverse CFrames here, which I can explain.
So an inverse CF…
4 Likes
Nogalo
(Nogalo)
November 2, 2020, 6:47am
#3
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)