I am struggling to add an offset to the camera module, I added the following to add Y offset of 3 without luck. Welp!
local myChar = script.Parent
local myHum = myChar.Humanoid
myHum.CameraOffset = Vector3.new(0,3,0)
Also, I m so so very happy with this module, BIG thank you! and if you have time and if you are interested, I would love to show you what I am doing with it
I’m having a bit of a struggle with the first person stuff. Everything works great at the start but once I go into first person then come out, the camera weighting stops working. I got no errors and would be grateful if you could point me in the right direction.
Source Code
local RUN_SERVICE = game:GetService("RunService")
local USER_INPUT_SERVICE = game:GetService("UserInputService")
local Cam = workspace.CurrentCamera
local Subject = script:WaitForChild("CameraSub")
local Head = script.Parent:WaitForChild("Head")
local Root = script.Parent:WaitForChild("HumanoidRootPart")
local Humanoid = script.Parent:WaitForChild("Humanoid")
Subject.Position = Head.Position
Cam.CameraSubject = Subject
local CamWeight = 60
local function UpdateSub()
if (Cam.CFrame.Position - Subject.Position).Magnitude < 1 or (Cam.CFrame.Position - Head.Position).Magnitude < 1 then
Cam.CameraSubject = Humanoid
Subject.Position = Head.Position
else
Subject.Position = Subject.Position:Lerp(Head.Position, 1/CamWeight)
if USER_INPUT_SERVICE.MouseBehavior == Enum.MouseBehavior.LockCenter then
local Look = Vector3.new(Cam.CFrame.LookVector.X, 0, Cam.CFrame.LookVector.Z)
Root.CFrame = CFrame.lookAt(Root.Position, Root.Position + Look)
end
end
end
RUN_SERVICE:BindToRenderStep("UpdateSub", Enum.RenderPriority.Camera.Value, UpdateSub)
works great but up close there’s still a slight stutter/jitter. how do you fix that?
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local head = script.Parent:WaitForChild("Head")
local subject = script:WaitForChild("Subject")
subject.Position = head.Position
camera.CameraSubject = subject
local WEIGHT = 20
local function updateSubject()
subject.Position = subject.Position:Lerp(head.Position,1/WEIGHT)
end
RunService:BindToRenderStep("UpdateSubject", Enum.RenderPriority.Camera.Value + 1, updateSubject)
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local CurrentCamera = workspace.CurrentCamera
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Head = script.Parent:WaitForChild("Head")
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local Subject = script:WaitForChild("Subject")
local HeadPosition = Head.Position
local SubjectPosition = Subject.Position
SubjectPosition = HeadPosition
CurrentCamera.CameraSubject = Subject
local SubjectWeights_Horizontal = 10
local SubjectWeights_Vertical = 20
local function UpdateSubject()
local OffsetVectors = Vector3.new(0, 0.6, 0)
local HorizontalPosition = Vector3.new(SubjectPosition.X, 0, SubjectPosition.Z):Lerp(Vector3.new(HeadPosition.X, 0, HeadPosition.Z) + OffsetVectors, 1/SubjectWeights_Horizontal)
local VerticalPosition = Vector3.new(0, SubjectPosition.Y, 0):Lerp(Vector3.new(0, HeadPosition.Y, 0) + OffsetVectors, 1/SubjectWeights_Vertical)
SubjectPosition = HorizontalPosition + VerticalPosition
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
local LookVectors = Vector3.new(CurrentCamera.CFrame.LookVector.X, 0, CurrentCamera.CFrame.LookVector.Z)
HumanoidRootPart.CFrame = CFrame.lookAt(HumanoidRootPart.Position, HumanoidRootPart.Position + LookVectors)
if (CurrentCamera.CFrame.Position - SubjectPosition).Magnitude < 1 or (CurrentCamera.CFrame.Position - HeadPosition).Magnitude < 1 then
CurrentCamera.CameraSubject = Humanoid
SubjectPosition = HeadPosition
else
CurrentCamera.CameraSubject = Subject
SubjectPosition = HorizontalPosition + VerticalPosition
end
end
end
RunService:BindToRenderStep("UpdateSubject", Enum.RenderPriority.Camera.Value, UpdateSubject)
It seems that I have ran into an issue, any idea why this is broken? I mean it seems to work but the camera doesn’t actually follow the player anymore?
It seems you are updating the variable SubjectPosition rather than the actual position of the subject part, so instead of changing the value of Subject.Position you’re just changing what value is stored in the SubjectPosition variable.
So inside the loop you should replace SubjectPosition with Subject.Position so that it is actually changing the position property. Also inside the loop you need to change HeadPosition to Head.Position so that you’re referring to the current position of the head rather than what the head position was when you originally defined that variable.
This post is pretty old so message me if you have any questions, but a better alternative is humanoid camera offset. You can lerp the camera offset to give the same effect with basically no delay.
local runs = game:GetService("RunService")
local char = script.Parent
local head = char:WaitForChild("Head")
local humanoid = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
-- Variables
local subject = script:WaitForChild("Subject")
subject.Position = head.Position
camera.CameraSubject = subject
local WEIGHT = 20
local function updateSubject()
if (camera.CFrame.Position - subject.Position).Magnitude < 1 or (camera.CFrame.Position - head.Position).Magnitude < 1 then
camera.CameraSubject = humanoid
subject.Position = head.Position
else
camera.CameraSubject = subject
subject.Position = subject.Position:Lerp(head.Position,1/WEIGHT)
end
end
runs:BindToRenderStep("UpdateSubject", Enum.RenderPriority.Camera.Value, updateSubject)
When I go into first person, it does this epilepsy effect. Is there anyway it can be fixed?