I am trying to make a camera follow a npc in an infinite corridor, and I wanted to add some camera shaking to look like you’re walking, but I’ve came across this problem wich makes the camera turn to one side, but instead of going to the other side, it goes back into the start position.
local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local run = game:GetService("RunService")
local is = ""
local Waifu = game.Workspace.ZeroTwo
script.Parent.MouseButton1Click:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = camPart.CFrame
script.Parent.Parent.Parent.Enabled = false
is = false
end)
local leftOrRight = false
local count = 25
run.RenderStepped:Connect(function(delta)
wait()
if not is then
local corridor = game.Workspace.Corridor:Clone()
corridor:SetPrimaryPartCFrame(corridor.PrimaryPart.CFrame * CFrame.new(0,0,-1))
game.Workspace.Corridor:Destroy()
corridor.Parent = game.Workspace
cam.CFrame = cam.CFrame * CFrame.new(0,0,-1)
Waifu.PrimaryPart.CFrame = Waifu.PrimaryPart.CFrame * CFrame.new(0,0,-1)
print("s")
is = true
elseif leftOrRight == false and is ~= "" then
local corridor = game.Workspace.Corridor:Clone()
corridor:SetPrimaryPartCFrame(corridor.PrimaryPart.CFrame * CFrame.new(0,0,-1))
game.Workspace.Corridor:Destroy()
corridor.Parent = game.Workspace
cam.CFrame = cam.CFrame * CFrame.new(0,0,-1) * CFrame.Angles(0,0,math.rad(-1))
Waifu.PrimaryPart.CFrame = Waifu.PrimaryPart.CFrame * CFrame.new(0,0,-1)
count = count - 1
if count == 0 then
leftOrRight = true
count = 25
end
elseif leftOrRight == true and is ~= "" then
local corridor = game.Workspace.Corridor:Clone()
corridor:SetPrimaryPartCFrame(corridor.PrimaryPart.CFrame * CFrame.new(0,0,-1))
game.Workspace.Corridor:Destroy()
corridor.Parent = game.Workspace
cam.CFrame = cam.CFrame * CFrame.new(0,0,-1) * CFrame.Angles(0,0,math.rad(1))
Waifu.PrimaryPart.CFrame = Waifu.PrimaryPart.CFrame * CFrame.new(0,0,-1)
count = count - 1
if count == 0 then
leftOrRight = false
count = 25
end
end
end)
I tried to fix that by doubling the angles into the other direction, but somehow it ended up like this:
local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local run = game:GetService("RunService")
local is = ""
local Waifu = game.Workspace.ZeroTwo
script.Parent.MouseButton1Click:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = camPart.CFrame
script.Parent.Parent.Parent.Enabled = false
is = false
end)
local leftOrRight = false
local count = 25
run.RenderStepped:Connect(function(delta)
wait()
if not is then
local corridor = game.Workspace.Corridor:Clone()
corridor:SetPrimaryPartCFrame(corridor.PrimaryPart.CFrame * CFrame.new(0,0,-1))
game.Workspace.Corridor:Destroy()
corridor.Parent = game.Workspace
cam.CFrame = cam.CFrame * CFrame.new(0,0,-1)
Waifu.PrimaryPart.CFrame = Waifu.PrimaryPart.CFrame * CFrame.new(0,0,-1)
print("s")
is = true
elseif leftOrRight == false and is ~= "" then
local corridor = game.Workspace.Corridor:Clone()
corridor:SetPrimaryPartCFrame(corridor.PrimaryPart.CFrame * CFrame.new(0,0,-1))
game.Workspace.Corridor:Destroy()
corridor.Parent = game.Workspace
cam.CFrame = cam.CFrame * CFrame.new(0,0,-1) * CFrame.Angles(0,0,math.rad(-1))
Waifu.PrimaryPart.CFrame = Waifu.PrimaryPart.CFrame * CFrame.new(0,0,-1)
count = count - 1
if count == 0 then
leftOrRight = true
count = 25
end
elseif leftOrRight == true and is ~= "" then
local corridor = game.Workspace.Corridor:Clone()
corridor:SetPrimaryPartCFrame(corridor.PrimaryPart.CFrame * CFrame.new(0,0,-1))
game.Workspace.Corridor:Destroy()
corridor.Parent = game.Workspace
cam.CFrame = cam.CFrame * CFrame.new(0,0,-1) * CFrame.Angles(0,0,math.rad(2)) -- changed from 1 to 2
Waifu.PrimaryPart.CFrame = Waifu.PrimaryPart.CFrame * CFrame.new(0,0,-1)
count = count - 1
if count == 0 then
leftOrRight = false
count = 25
end
end
end)
Thanks in advance!
Edit: messed up the code block, it’s fixed now.