Found the solution. It was just the matter of using RightVector and LeftVector of the own camera, figuring out the direction. Here’s the code:
function inputBegan(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.A then
while UserInputService:IsKeyDown(Enum.KeyCode.A) do
local direction = -Camera.CFrame.RightVector -- Left Vector
local x, z = clamp(direction.X, -1, 1), clamp(direction.Z, -1, 1)
cameraPart.CFrame = cameraPart.CFrame:Lerp(cameraPart.CFrame + Vector3.new(x, 0, z), .75)
task.wait()
end
elseif input.KeyCode == Enum.KeyCode.D then
while UserInputService:IsKeyDown(Enum.KeyCode.D) do
local direction = Camera.CFrame.RightVector
local x, z = clamp(direction.X, -1, 1), clamp(direction.Z, -1, 1)
cameraPart.CFrame = cameraPart.CFrame:Lerp(cameraPart.CFrame + Vector3.new(x, 0, z) , .75)
task.wait()
end
elseif input.KeyCode == Enum.KeyCode.W then
while UserInputService:IsKeyDown(Enum.KeyCode.W) do
local direction = -Camera.CFrame.LookVector
local x, z = clamp(direction.X, -1, 1), clamp(direction.Z, -1, 1)
cameraPart.CFrame = cameraPart.CFrame:Lerp(cameraPart.CFrame + Vector3.new(-x, 0, -z), .75)
task.wait()
end
elseif input.KeyCode == Enum.KeyCode.S then
while UserInputService:IsKeyDown(Enum.KeyCode.S) do
local direction = -Camera.CFrame.LookVector
local x, z = clamp(direction.X, -1, 1), clamp(direction.Z, -1, 1)
cameraPart.CFrame = cameraPart.CFrame:Lerp(cameraPart.CFrame + Vector3.new(x, 0, z), .75)
task.wait()
end
-- Rotation
elseif input.KeyCode == Enum.KeyCode.E then
-- Rotate to the right
while UserInputService:IsKeyDown(Enum.KeyCode.E) do
rotation -= 2.5
task.wait()
end
elseif input.KeyCode == Enum.KeyCode.Q then
-- Rotate to the left
while UserInputService:IsKeyDown(Enum.KeyCode.Q) do
rotation += 2.5
task.wait()
end
end
end
end
function onRenderStepped(dt)
local partPos = cameraPart.Position
local offset = CFrame.new(OFFSET, OFFSET, OFFSET)
local cf = cameraPart.CFrame * CFrame.Angles(0, math.rad(rotation), 0) * offset
Camera.CFrame = CFrame.new(cf.p, partPos)
end
Either way, thank you for your suggestions.