Camera following cursor is a bit janky

trying to make a simple menu screen where the camera follows the cursor, but the tween is really… not good. any ideas on what i can do please feel free to share

video showing the jank in question

https://gyazo.com/9b1f7198cb0299ab1e355f366e9e705e

my code is as follows

-- cc = current camera, campart1 = the camera part

local mouse = game.Players.LocalPlayer:GetMouse()

cc.CameraSubject = mouse
local debounce = false

mouse.Move:Connect(function()
	
	if not debounce then
		
		cc.CameraSubject = mouse
		cc.CFrame = campart1.CFrame
		
		local tween = tws:Create(cc, TweenInfo.new(), {CFrame = CFrame.new(campart1.Position, mouse.Hit.p)})
		tween:Play()
		
		debounce = true
		
		tween.Completed:Wait()
		
		debounce = false

	end

end)

2 Likes

i dont think thats a good way for a ‘camera follow’. a much better method is to use a lerp instead.

1 Like

Why is there a tween at all if you want the camera to follow the cursor, just point it to where the cursor point is in world every renderstep.

1 Like

Greetings, I have been using this script for awhile for alot of my games and it has worked really well for me. If you need help best suiting it for your use case please let me know but this is the basics on how I have it set up!

local Mouse = game.Players.LocalPlayer:getMouse()
local Camera = game.Workspace.CurrentCamera

local CameraPart = workspace:WaitForChild("CameraPart")

local Scale = 200 --The lower the number is the more does your camera follow your mouse

function Update()
	local Center = Vector3.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)

	local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, (Mouse.Y-Center.Y)/Scale, 10)

	Camera.CFrame = CameraPart.CFrame * CFrame.Angles(math.rad(-(Mouse.Y-Center.Y)/Scale),math.rad(-(Mouse.X-Center.X)/Scale),0)
end

game["Run Service"].RenderStepped:Connect(Update)
2 Likes

actually you have a point… I’ll see what I can do.

yeah, I think I’ll look into that, thanks!

Thanks! I should’ve considered using the run service earlier :sweat_smile:

This works great :+1:

1 Like

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