Camera Bobble affecting my First Person body script

So I have a script that changes the players local transparency of their body to make it so they can see their body in first person. I also have a camera bobbing script but I noticed that the camera bobbing effects the character in first person and rotates their body around. I’m pretty sure that this is an issue with roblox’s default humanoid.AutoRotate code but if anyone has suggestions on how I could fix this it would be greatly appreciated.

Here is my code including the first person script and the camera bobbing(in starter character scripts btw):

local runService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

camera.FieldOfView = 90
--humanoid.AutoRotate = false
camera.CameraType = Enum.CameraType.Custom
--player.CameraMaxZoomDistance = 0.5 -- force first person
--player.CameraMode = Enum.CameraMode.LockFirstPerson
humanoid.CameraOffset = Vector3.new(0, -.6, -1)

humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed then
		script.RemoteEvent:FireServer()
	else
  end
end)

-- set and keep every body part Transparency to its real transparency
for childIndex, child in pairs(character:GetChildren()) do
	if child:IsA("BasePart") and child.Name ~= "Head" and child.Name ~= "Torso" then

		child:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			child.LocalTransparencyModifier = child.Transparency
		end)

		child.LocalTransparencyModifier = child.Transparency
	end
end

Z = 0

local damping = humanoid.WalkSpeed/4 

local PI = 3.1415926
local tick = PI / 2

function mix(p3, p4, p5)
	return p4 + (p3 - p4) * p5;
end
while true do
	local step = game:GetService("RunService").RenderStepped:wait()

	if humanoid.MoveDirection.Magnitude > 0 then
		tick = tick + humanoid.WalkSpeed / 102 * (30*step)
	else
		if tick > 0 and tick < PI / 2 then
			tick = mix(tick, PI / 2, 0.9)
		end;
		if PI / 2 < tick and tick < PI then
			tick = mix(tick, PI / 2, 0.9)
		end;
		if PI < tick and tick < PI * 1.5 then
			tick = mix(tick, PI * 1.5, 0.9)
		end;
		if PI * 1.5 < tick and tick < PI * 2 then
			tick = mix(tick, PI * 1.5, 0.9)
		end;
	end;
	if PI * 2 <= tick then
		tick = 0;
	end
	camera.CFrame *= CFrame.new(math.cos(tick) / damping, math.sin(tick * 2) / (damping * 2), Z) * CFrame.Angles(0, 0, math.sin(tick - PI * 1.5) / (damping * 20))
end

Video of the issue:

1 Like

Found a fix for this. I ended up just setting the camera subject to the head and then changing the transparency of the players model as I wanted. And then I have a render stepped function that rotates my player to my look vector as I disabled auto rotate. This method also works much better with cframes and the camera.

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