Cant get CameraOffset to be set correctly

Hi, Im attempting to code a first person system and unfortunately ive run into a problem.

For some reason, the code only seems to set the player’s CameraOffset to the correct position in one spot even though from visualizing the point in which theoretically the CameraOffset should be set (atleast I think), to the correct position always

Heres the code that I have

game["Run Service"].RenderStepped:Connect(function()
	if not setting and set then
		local lookvector = char.Head.CFrame.LookVector.Unit * script.OffsetAmt.Value
		
		local headOffset = (char.Head.Position - (char.HumanoidRootPart.Position + Vector3.new(0,1.5,0))) + lookvector
		
		local part = Instance.new("Part",workspace)
		part.Size = Vector3.one/4
		part.Material = Enum.Material.Neon
		part.Position = (char.HumanoidRootPart.Position + Vector3.new(0,1.5,0)) + headOffset
		part.Anchored = true
		part.CanCollide = false
		game.Debris:AddItem(part,3)
		
		hum.CameraOffset = headOffset
		
	end
end)

the solution is probably something easy that im just not realizing but ive tried looking it up and asking my friends and cant seem to find an answer, so any help would be appreciated, Thanks.

oh OffsetAmt is set to 0.75 i should probably mention that

turns out i cannot do math, and the way i was going about doing this was wrong

local headCurPos:Vector3 = char.Head.Position + char.Head.CFrame.LookVector.Unit*.75
local headOGPos:Vector3 = char.HumanoidRootPart.Position + Vector3.new(0,1.5,0)
		
local vec1 = Vector3.new(headCurPos.X,headOGPos.Y,headCurPos.Z)
local mag = (vec1-headOGPos).Magnitude
		
local vec2 = Vector3.new(headOGPos.X,headCurPos.Y,headOGPos.Z)
local mag2 = (vec2-headOGPos).Magnitude
		
f headCurPos.Y < headOGPos.Y then
	mag2 = -mag2
end

hum.CameraOffset = Vector3.new(0,mag2,-math.abs(mag))

this was what I came up with as a replacement and it seems to work exactly how I wanted.

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