Hey there! I have made a wallrun script, which works perfectly fine, other than the camera tilting. It does tilt, but it’s very snappy and doesn’t go smoothly.
Here’s the piece of code that makes the camera tilt:
local tiltLoop = game:GetService("RunService").RenderStepped:Connect(function()
if wallL then
cam.CFrame = cam.CFrame:Lerp(CFrame.lookAt(cam.CFrame.Position, cam.CFrame.Position + cam.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(-10)), .3)
elseif wallR then
cam.CFrame = cam.CFrame:Lerp(CFrame.lookAt(cam.CFrame.Position, cam.CFrame.Position + cam.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(10)), .3)
end
end)
As you can see I’ve tried using Lerp, but it didn’t work. I’ve tried tweening as well (outside of the loop), but that didn’t work either. Any way I can do this? Any help is appreciated!
local function TiltCamera(bool)
if bool then
tiltLoop = game:GetService("RunService").RenderStepped:Connect(function()
if wallL then
for i=.1,1,.1 do
cam.CFrame = cam.CFrame:Lerp(CFrame.lookAt(cam.CFrame.Position, cam.CFrame.Position + cam.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(-10)), .3)
wait(.01)
end
elseif wallR then
for i=.1,1,.1 do
cam.CFrame = cam.CFrame:Lerp(CFrame.lookAt(cam.CFrame.Position, cam.CFrame.Position + cam.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(10)), .3)
wait(.01)
end
end
end)
else
if tiltLoop then
tiltLoop:Disconnect()
tiltLoop = nil
end
end
end
I placed it into a function as well. Should I remove the RenderStepped loop?
Debounce makes the camera tilt and go back to it’s position really quickly, since the renderstepped loop makes sure the rotation gets changed every frame. If I stop the loop, the camera automatically goes back to normal.
The for loop does take .1 seconds to be completed .01 secs is practically the same as it not being there
You can reduce the increase per loop or up the wait, lower the increase smoother it is
I feel like i may be missunderstanding something, let me know if so.
So this is what I have done, and it seems to have worked!
local function TiltCamera(bool)
if bool then
tiltLoop = game:GetService("RunService").RenderStepped:Connect(function()
if wallL then
cam.CFrame = cam.CFrame:Lerp(CFrame.lookAt(cam.CFrame.Position, cam.CFrame.Position + cam.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(-tiltL)), .3)
elseif wallR then
cam.CFrame = cam.CFrame:Lerp(CFrame.lookAt(cam.CFrame.Position, cam.CFrame.Position + cam.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(tiltR)), .3)
end
end)
delay(0, function()
while wallrunning and tiltL < 10 and tiltR < 10 do
tiltL += increment
tiltR += increment
wait(.01)
end
end)
else
if tiltLoop then
while tiltL > 0 and tiltR > 0 do
tiltL -= 10/3
tiltR -= 10/3
wait(.01)
end
tiltLoop:Disconnect()
tiltLoop = nil
end
end
end
I basically just increase the tilt in a while loop with a set increment (in my case increment=2). I put in inside of a delay, so the rest of the code after function could run. For some reason the lerp does work in this method and smooths it out.
(Edit: I’ve made exiting the wallrun smoother as well)