I want to make a custom-made camera, but I have an issue. I apply an offset, a Vector3 to the subject position (the HumanoidRootPart). And it doesn’t really follow the camera’s look direction, so I converted it to the camera CFrame’s vector world space using:
Camera.CFrame:VectorToWorldSpace(Offset)
Now, It did work quite well, but I have a major issue that this solution causes: jittering and delays (lag behinds). As seen in the gif below:
So far, I did try applying the mouse’s delta (with deltaTime) to the converted offset and the camera’s CFrame, but that didn’t seem to work aswell.
This is my camera’s update code:
local function GetCameraAngles(Camera: Camera, Horizontal: number, Vertical: number): (number, number)
local Delta = UserInputService:GetMouseDelta() * UserGameSettings.MouseSensitivity * Constants.SensitivityMultiplier
Horizontal -= Delta.X / Camera.ViewportSize.X
Vertical -= Delta.Y / Camera.ViewportSize.Y
Vertical = math.rad(math.clamp(math.deg(Vertical), Constants.VerticalLimit.Min, Constants.VerticalLimit.Max))
return Horizontal, Vertical
end
local function CalculateOffset(Camera: Camera): Vector3
local InitialOffset = Global.CameraOffset
local Delta = UserInputService:GetMouseDelta()
Delta *= math.min(ECS.useDeltaTime(), 0.1) * 0.5 -- ECS.useDeltaTime() returns the deltaTime, i made sure of it.
InitialOffset = (CFrame.Angles(0, -Delta.X, 0) * Camera.CFrame * CFrame.Angles(-Delta.Y, 0, 0)):VectorToWorldSpace(InitialOffset)
return InitialOffset
end
local function Calculate(RootPart: BasePart, Camera: Camera, HorizontalAngle: number, VerticalAngle: number): CFrame
local HorizontalRotation = CFrame.Angles(0, HorizontalAngle, 0)
local VerticalRotation = CFrame.Angles(VerticalAngle, 0, 0)
local Offset = CalculateOffset(Camera)
return CFrame.new(RootPart.Position) * (HorizontalRotation * VerticalRotation)
end