In my game, there's a mechanic where you can edit a wall and put stuff on it.
I haven't done any progress on the editing but I did with my camera scrolling.
So, my goal is to make it so the camera goes into a side-scroller state.
Temporarily, I made a part which lets me go into this state.
This is the script for the part which puts the player's camera to the CFrame of the part.
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local rp = game:GetService("ReplicatedStorage")
local debounce = false
workspace.Interactables.CameraPart.Touched:Connect(function(hit)
if hit.Parent == game:GetService("Players").LocalPlayer.Character and not debounce then
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = workspace.CameraStart.CFrame
for _, Button in pairs(rp.GuiButtons:GetChildren()) do
if Button.Name == "EditorButton" then
Button:Clone().Parent = player.PlayerGui
end
end
end
end)
I didn't know a method on how to say if the player has the button to go back so I used debounce, there's probably a better way.
Now, in this script, I made two versions of the camera script. But, both of them doesn't meet my expectations of a side scroller
Here's the script:
-- Services
local uis = game:GetService("UserInputService")
-- Variables
local cam = workspace.CurrentCamera
local startingPosition = workspace.CameraStart
local wall = workspace.EditingWall
--[[ Correct Way, But not smooth
uis.InputBegan:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.A then
cam.CFrame = cam.CFrame * CFrame.new(-1,0,0)
elseif input.KeyCode == Enum.KeyCode.D then
cam.CFrame = cam.CFrame * CFrame.new(1,0,0)
elseif input.KeyCode == Enum.KeyCode.S then
cam.CFrame = cam.CFrame * CFrame.new(0,-1,0)
elseif input.KeyCode == Enum.KeyCode.W then
cam.CFrame = cam.CFrame * CFrame.new(0,1,0)
end
end)
]]--
--[[ Not the solution I was looking for
uis.InputBegan:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.A then
cam:Interpolate(cam.CFrame*CFrame.new(-1,0,0), wall.CFrame, 1)
elseif input.KeyCode == Enum.KeyCode.D then
cam:Interpolate(cam.CFrame*CFrame.new(1,0,0), wall.CFrame, 1)
elseif input.KeyCode == Enum.KeyCode.S then
cam:Interpolate(cam.CFrame*CFrame.new(0,-1,0), wall.CFrame, 1)
elseif input.KeyCode == Enum.KeyCode.W then
cam:Interpolate(cam.CFrame*CFrame.new(0,1,0), wall.CFrame, 1)
end
end)
]]--
Now, I have a problem where if I went back to the player, the script above still activates which I don't want to happen.
This is the script for the go back to player script
local player = game.Players.LocalPlayer
local char = player.Character or player.CharactedAdded:Wait()
local cam = workspace.CurrentCamera
script.Parent.MouseButton1Down:Connect(function()
cam.CameraType = "Scriptable"
cam.CameraSubject = char:WaitForChild("Humanoid")
cam.CameraType = "Custom"
script.Parent.Parent.Parent:Destroy()
end)
Edit: Tried using lerp on the camera script.
uis.InputBegan:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.A then
for i=0,1,0.1 do
cam.CFrame:lerp(cam.CFrame*CFrame.new(-1,0,0), i)
end
elseif input.KeyCode == Enum.KeyCode.D then
for i=0,1,0.1 do
cam.CFrame:lerp(cam.CFrame*CFrame.new(1,0,0), i)
end
elseif input.KeyCode == Enum.KeyCode.S then
for i=0,1,0.1 do
cam.CFrame:lerp(cam.CFrame*CFrame.new(0,1,0), i)
end
elseif input.KeyCode == Enum.KeyCode.W then
for i=0,1,0.1 do
cam.CFrame:lerp(cam.CFrame*CFrame.new(0,1,0), i)
end
end
end)
-- PS. It doesn't work. >_<
I'm probably wrong with implementing lerp. I don't know.
Thanks for the help in advance!!! :33

2 comments
make more cframes. that might help
that is so vague.