– [[ Normal Varibels ]] –
local Player = game.Players.LocalPlayer
local Char = workspace:WaitForChild(Player.Name).Char
local Cam = game.Workspace.CurrentCamera
local Mouse = Player:GetMouse()
local Uis = game:GetService(“UserInputService”)
local Run = game:GetService(“RunService”)
local Ts = game:GetService(“TweenService”)
local CameraSettings = require(game.ReplicatedStorage.CameraSettings)
– [[ Constructure Varibels ]] –
local CAMERASPEED = CameraSettings.CameraMoveSpeed
– [[ Settings ]] –
Cam.CameraType = CameraSettings.CameraType
Cam.CFrame = CFrame.new(0,0,0)
Cam.CFrame = Char.CFrame
– [[ Camera Functionality ]] –
local W,A,S,D,NotMoving = false,false,false,false,true
–// Making Player Keep Moving
local function KeepMoving()
repeat
if W then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.ZVector * -CAMERASPEED)
end
if S then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.ZVector * CAMERASPEED)
end
if A then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * -CAMERASPEED)
end
if D then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * CAMERASPEED)
end
Char.CFrame = Cam.CFrame
Run.RenderStepped:Wait()
until NotMoving
end
–// When Player Starts Moving
local function MoveBegan(actionName,inputState,input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if Uis:IsKeyDown(Enum.KeyCode.W) then
W = true
NotMoving= false
end
if Uis:IsKeyDown(Enum.KeyCode.A) then
A = true
NotMoving= false
end
if Uis:IsKeyDown(Enum.KeyCode.S) then
S = true
NotMoving= false
end
if Uis:IsKeyDown(Enum.KeyCode.D) then
D = true
NotMoving= false
end
end
if W and not S and not D and not A then
KeepMoving()
elseif not W and not S and not D and A then
KeepMoving()
elseif not W and not S and not D and A then
KeepMoving()
elseif not W and not S and not D and A then
KeepMoving()
end
end
–// When Player Stops Moving
local function MoveEnded(input, gpe)
if input.KeyCode == Enum.KeyCode.W then
W = false
elseif input.KeyCode == Enum.KeyCode.S then
S = false
elseif input.KeyCode == Enum.KeyCode.D then
D = false
elseif input.KeyCode == Enum.KeyCode.A then
A = false
end
end
if not W and not S and not D and not A then
NotMoving = true
else
NotMoving = false
end
Uis.InputChanged:Connect(function(InputObject)
if InputObject.UserInputType == Enum.UserInputType.MouseMovement then
local LookAt = Vector3.new(-InputObject.Delta.Y / 300, -InputObject.Delta.X / 300, 0)
Cam.CFrame = Cam.CFrame * CFrame.fromEulerAngles(
LookAt.X,
LookAt.Y,
0
)
end
end)
game:GetService(“ContextActionService”):BindAction(“MoveCam” , MoveBegan, false,Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D)
Uis.InputEnded:Connect(MoveEnded)
Mouse.Button2Down:Connect(function()
Uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end)
Mouse.Button2Up:Connect(function()
Uis.MouseBehavior = Enum.MouseBehavior.Default
end)