Hello Developers!
I’ve created a Local-Script under StarterCharacter called “2DCameraMovment”. The script function is to replicate those games where rather than the camera following your character, it allows you to simply move your camera freely, such as Lobotomy Corporation. The issue? It has to do with the camera move functions, it does move the camera, although it doesn’t repeatedly move while it’s corresponding arrow key is pressed. (For example, if I press the Left Arrow Key, the camera moves left but after a brief moment, it won’t move despite me holding the Left Arrow Key.)
local Camera = workspace.CurrentCamera
Camera.FieldOfView = 80
--Char--
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
--Services--
local CAS = game:GetService("ContextActionService")
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local RunS = game:GetService("RunService")
CAS:UnbindAction("moveForwardAction")
CAS:UnbindAction("moveBackwardAction")
CAS:UnbindAction("moveLeftAction")
CAS:UnbindAction("moveRightAction")
--Functions--
local function MoveCameraLeft()
local Goal = {
CFrame = Camera.CFrame * CFrame.new(-30, 0, 0)
}
local Tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local Tween = TS:Create(Camera,Tweeninfo,Goal)
Tween:Play()
task.wait()
end
local function MoveCameraRight()
local Goal = {
CFrame = Camera.CFrame * CFrame.new(30, 0, 0)
}
local Tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local Tween = TS:Create(Camera,Tweeninfo,Goal)
Tween:Play()
task.wait()
end
local function MoveCameraUp()
local Goal = {
CFrame = Camera.CFrame * CFrame.new(0, 30, 0)
}
local Tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local Tween = TS:Create(Camera,Tweeninfo,Goal)
Tween:Play()
task.wait()
end
local function MoveCameraDown()
local Goal = {
CFrame = Camera.CFrame * CFrame.new(0, -30, 0)
}
local Tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local Tween = TS:Create(Camera,Tweeninfo,Goal)
Tween:Play()
task.wait()
end
RunS.RenderStepped:Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
--Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(hrp.Position + Vector3.new(0, 5, 10), hrp.Position), 0.1)
UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
if Input.UserInputType == Enum.UserInputType.Keyboard then
if Input.KeyCode == Enum.KeyCode.Left then
if UIS:IsKeyDown(Enum.KeyCode.Left) then
MoveCameraLeft()
task.wait()
end
end
if Input.KeyCode == Enum.KeyCode.Right then
if UIS:IsKeyDown(Enum.KeyCode.Right) then
MoveCameraRight()
task.wait()
end
end
if Input.KeyCode == Enum.KeyCode.Up then
if UIS:IsKeyDown(Enum.KeyCode.Up) then
MoveCameraUp()
task.wait()
end
end
if Input.KeyCode == Enum.KeyCode.Down then
if UIS:IsKeyDown(Enum.KeyCode.Down) then
MoveCameraDown()
task.wait()
end
end
end
end)
end)