View Bobbing causes weird model movements

  1. I want to achieve a first person view bobbing without making the body move around camera

  2. Issue is that i have a script that makes characters body visible in first person but in first person it weirldy moves and rotates around camera

  3. i tried disabling the view bobbing script but without it the game feels sour

Seeing body in first person code:

-- initialize local variables
wait(0.1)
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

-- camera settings
humanoid.CameraOffset = Vector3.new(0, 0, -0.7)

-- 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" then

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

		child.LocalTransparencyModifier = child.Transparency

	end
end

-- if the player steps in a vehicle
camera:GetPropertyChangedSignal("CameraSubject"):Connect(function()
	if camera.CameraSubject:IsA("VehicleSeat") then
		camera.CameraSubject = humanoid
	end
end)

and this is the view bobbing code:

while true do
	wait();
	if game.Players.LocalPlayer.Character then
		break;
	end;
end;
camera = game.Workspace.CurrentCamera;
character = game.Players.LocalPlayer.Character;
Z = 0;
damping = character.Humanoid.WalkSpeed / 2;
PI = 3.1415926;
tick = PI / 2;
running = false;
strafing = false;
character.Humanoid.Strafing:connect(function(p1)
	strafing = p1;
end);
character.Humanoid.Jumping:connect(function()
	running = false;
end);
character.Humanoid.Swimming:connect(function()
	running = false;
end);
character.Humanoid.Running:connect(function(p2)
	if p2 > 0.1 then
		running = true;
		return;
	end;
	running = false;
end);
character.Humanoid.Died:connect(function()
	running = false;
end);
function mix(p3, p4, p5)
	return p4 + (p3 - p4) * p5;
end;
while true do
	local step = game:GetService("RunService").RenderStepped:wait();
	fps = (camera.CoordinateFrame.p - character.Head.Position).Magnitude;
	if fps < 0.52 then
		Z = 0;
	else
		Z = 0;
	end;
	if running == true and strafing == false then
		tick = tick + character.Humanoid.WalkSpeed / 102 * (60*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.CoordinateFrame = camera.CoordinateFrame * 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;

any help is appreciated :slight_smile:

  1. Instead of setting pi’s value like you are now, just use math.pi
  2. Refrain from putting semicolons after each line of your code.
  3. Edit the Humanoid.CameraOffset property instead of repeatedly changing the camera CFrame every frame.