Issue with camera movement

Hello. I’m trying to tween a tilt to the side of the players camera. When they move, I want the camera to tilt to the left, and after that’s done, tilt from there to the right side, and so on until the player stops moving. I can do everything apart from looping the two tween tilts. Any ideas?

2 Likes

Hey, TheGoldMiner! Based off of your question, I think I may have a solution to your problem!

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 / 3
PI = 3.1415926
tick = PI / 2
running = false
strafing = false
IsMoving = 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)

character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if character.Humanoid.MoveDirection.Magnitude == 0 then
		IsMoving = false
	else
		IsMoving = true
	end
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 and IsMoving == true then
		tick = tick + character.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.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
2 Likes

As not to delete this one too, I’ll just edit it. You don’t need to respond. I figured it out. Thank you so much.

Last question was stupid so I deleted it.

Which part controls the speed? I know damping is how far it goes, but how’d I modify speed of the tilts? Thank you in advance, you’re a legend.

1 Like