Make camera script less laggy and glitchy

Hello.

I am currently making an RPG game with a third person view.
And as I am not good and math related programming nor cameras. I got this script from this thread.

And I am currently using @ImFarley script. And as it works just like I want it too. It is (no offence) quite laggy and glitchy if I may say.

Hey, I can’t even make one so it sounds a bit complaining (which I am not!).

But, I was wondering if there was any better way of doing this and make it more smooth.

One of my favourite games POLYGUNS does this in a great way, and @SnakeWorl one of the creators, has managed that fine (maybe you also can aid me?).

Game link:
ThirdPersonCamera.rbxl (18.7 KB)

And here is a gif, showing what I mean.
https://gyazo.com/7727cc26e56df14dda932246e30e4251

Thank you very much for all help, and again. Thank you @ImFarley

So anyway, here is the script.

local ts = game:GetService(“TweenService”)
local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
repeat wait() until plr.Character and plr.Character.Parent == workspace

local char = plr.Character
local hum = char:WaitForChild(“Humanoid”)
local waist = char.UpperTorso:WaitForChild(“Waist”)
local root = char:WaitForChild(“HumanoidRootPart”)

hum.CameraOffset = Vector3.new(4, 0, 0)
hum.AutoRotate = false
cam.CameraSubject = hum

game:GetService(“RunService”).RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local delta = uis:GetMouseDelta()
local deltaX, deltaY = delta.X, -delta.Y
cam.CFrame = CFrame.new(cam.CFrame.p, cam.CFrame* CFrame.new(deltaX, deltaY, -2000).p)

local offset = char.LowerTorso.CFrame:ToWorldSpace(CFrame.new(0, char.UpperTorso.Size.Y/2, 0)) * CFrame.fromEulerAnglesXYZ(math.max(math.min(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), .6), -.75), 0, 0) * CFrame.new(0, char.UpperTorso.Size.Y/2, 0)

waist.C1 = offset:inverse() * char.LowerTorso.CFrame * CFrame.new(0, .8, 0)

local tweenInfo = TweenInfo.new(.15, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local newRootCF = CFrame.new(root.CFrame.p,root.CFrame.p+Vector3.new(cam.CFrame.lookVector.X,0,cam.CFrame.lookVector.Z))
local tween = ts:Create(root, tweenInfo, {[“CFrame”] = newRootCF}, true)
tween:Play()
end)```

I think the problem is related to the fact you’re tweening about 60x/s. There’s a 0.15s delay with overlapping tweens. Why are you tweening anyways? Just snap the position of the body to match the camera.

3 Likes

I made something that I think may be very similar to what you want a while ago.

Low fps because of studio stuff.

This one works pretty well performance wise. I was thinking of open-sourcing it but never got to actually doing it.

If you want to test my camera I’d gladly open the place up and possibly open-source it so you can use it.

3 Likes

Dude, I would love to test out that camera!

I have been searching for so long, that would be great!

Also, is it fairly easy to disable/enable, since I am interested in being able to turn it off.

But, yeah, would love to test that out! :grin:

Could you elaborate? On the snap?

1 Like

There is a few things I overlooked when making the camera that I’d have to fix but you can test it now. I’ll message you the link in a sec.

2 Likes

Just set the CFrame don’t tween it. Tweening in a loop like that is generally a bad idea.

1 Like

Yeah that code is pretty terrible.

The solution I eventually landed on was just setting the cameramode to mouse lock. Works like a charm.

1 Like

That’s what I also tried. But there is no good way to do it (if you want to be able to disable it again).

As far as I know. But thanks

Here ya go

1 Like

Thanks a lot, i’ll test both @NeonD00m‘s script and yours too see what works best.

Thanks again!

Keep in mind that tweening should be handled on the client unless it absolutely has to be handled on the server. It reduces the load on the server as well as making your tween appear much smoother.

1 Like