Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get this working without glitching?

Okay so I've been working on a camera roll script that will smoothly roll the camera kinda like tweening. I've gotten it to a certain extent but now, I have no idea what's glitching it. If you copy and paste the script below into a local script in studio, and then test it, it'll work exactly how it is working for me. I don't know how to fix that glitch so someone please help :(

wait(1)

local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local mouse = player:GetMouse()
local char = player.Character
local RS = game:GetService('RunService')

local target = char:WaitForChild("Head")
cam.CameraType = Enum.CameraType.Scriptable
cam.CameraSubject = target
 
game:GetService('RunService').RenderStepped:connect(function()
    cam.CoordinateFrame = CFrame.new(target.Position) + Vector3.new(0,0, 10)
end)

local v = 0
local Leaning = false 


function LeanCam(t,s)
RS.RenderStepped:wait()
while Leaning do
wait()
 v = v + (t - v) * s
 cam:SetRoll(v)
end
wait(0.15)
end

mouse.KeyDown:connect(function(Key)
 if Key == "q" then
Leaning = true
  LeanCam(-1,0.15)
Leaning = false
 end
end)

mouse.KeyUp:connect(function(Key)
 if Key == "q" then
Leaning = true
  LeanCam(1,0.15)
Leaning = false
 end
end)

1 comment

0

I haven't worked too much with cameras, so this is a bit of a guess, but I believe instead of adding a Vector3 on line 14, you should be multiplying a CFrame.new value. If that doesn't work, I would have to test this myself and experiment around with it. Good Luck!

1 answer

✓ Accepted answer

The organization of your code makes no sense.


You have a target value target, and and a rate to approach target, s, which is always 0.15.

While the Q key is held down, you want target to be -1, and while it's not held down, you want target to be 1.

Just do that, then:

local target = 0

mouse.KeyDown:connect(function(Key)
	if Key == "q" then
		target = -1
	end
end)

mouse.KeyUp:connect(function(Key)
	if Key == "q" then
		target = 1
	end
end)

local v = 0
while true do
	wait()
	v = v + (target - v) * .15
	cam:SetRoll(v)
end

Since you're setting the camera, that while loop should be probably be waiting for RenderStepped or Heartbeat instead of just using wait().

1 comment

0

Well target is set to the characters head because you can't roll the camera without setting the camera type to scriptable. When set to scriptable, you need to render step the cameras frame to the head or the camera won't move with the player.

This discussion is preserved as it was. New answers, comments, and votes are closed.