Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- EDITABLE VALUES
- -- Activation keys -> Enum.KeyCode
- local InvisibilityKey = Enum.KeyCode.Y
- local FlyKey = Enum.KeyCode.T
- -- Motion keys -> Enum.KeyCode
- local ForwardMoveKey = Enum.KeyCode.W
- local BackwardMoveKey = Enum.KeyCode.S
- local LeftMoveKey = Enum.KeyCode.A
- local RightMoveKey = Enum.KeyCode.D
- local UpMoveKey = Enum.KeyCode.E
- local DownMoveKey = Enum.KeyCode.Q
- local MoreSpeedKey = Enum.KeyCode.LeftShift --> Like the run key from a game
- -- Speed values -> number
- local acceleration = 0.6
- local minSpeed = 30
- local maxSpeed = 100
- -- ONLY TOUCH THE THINGS UNDER THIS COMMENT IF YOU KNOW WHAT ARE YOU DOING
- local player:Player? = game:GetService("Players").LocalPlayer
- local character:Model? = player.Character
- local humanoid:Humanoid = character:WaitForChild("Humanoid")
- local humanoidWalkSpeed = humanoid.WalkSpeed
- local currentCamera = workspace.CurrentCamera
- local HumanoidRootPart = character.PrimaryPart
- local userInputService = game:GetService("UserInputService")
- local isCamera = false
- local playerMouse = player:GetMouse()
- local forwardMove = 0
- local backwardMove = 0
- local upMove = 0
- local downMove = 0
- local rightMove = 0
- local leftMove = 0
- local moveSpeed = minSpeed
- local aumentSpeed = false
- local currentCameraRotation = Vector3.new(0,0,0)
- local function SwitchBoolean(boolValue:boolean):boolean
- if boolValue then
- return false
- else
- return true
- end
- end
- local function SetPartsAnchoredValue(value:boolean)
- for index, child in pairs(character:GetChildren()) do
- if child:IsA("BasePart") then
- child.Anchored = value
- end
- end
- end
- local isAnchored = false
- local inputBeganSignal = userInputService.InputBegan:Connect(function(input:InputObject, gameP:boolean)
- if not gameP then
- if input.KeyCode == FlyKey and not isCamera then
- isAnchored = SwitchBoolean(isAnchored)
- SetPartsAnchoredValue(isAnchored)
- end
- if input.KeyCode == InvisibilityKey then
- isCamera = SwitchBoolean(isCamera)
- if isCamera then
- SetPartsAnchoredValue(false)
- isAnchored = false
- userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
- currentCamera.CameraType = Enum.CameraType.Scriptable
- currentCamera.CFrame = character.Head.CFrame
- humanoid.WalkSpeed = 0
- else
- SetPartsAnchoredValue(false)
- isAnchored = false
- character.PrimaryPart.CFrame = currentCamera.CFrame
- humanoid.WalkSpeed = humanoidWalkSpeed
- userInputService.MouseBehavior = Enum.MouseBehavior.Default
- currentCamera.CameraType = Enum.CameraType.Custom
- end
- end
- if input.KeyCode == ForwardMoveKey then
- forwardMove = moveSpeed
- backwardMove = 0
- elseif input.KeyCode == BackwardMoveKey then
- backwardMove = moveSpeed
- forwardMove = 0
- end
- if input.KeyCode == LeftMoveKey then
- leftMove = moveSpeed
- rightMove = 0
- elseif input.KeyCode == RightMoveKey then
- rightMove = moveSpeed
- leftMove = 0
- end
- if input.KeyCode == UpMoveKey then
- upMove = moveSpeed
- downMove = 0
- elseif input.KeyCode == DownMoveKey then
- downMove = moveSpeed
- upMove = 0
- end
- if input.KeyCode == MoreSpeedKey then
- aumentSpeed = true
- end
- end
- end)
- local inputEndedsignal = userInputService.InputEnded:Connect(function(input:InputObject, gameP:boolean)
- if not gameP then
- if input.KeyCode == ForwardMoveKey then
- forwardMove = 0
- end
- if input.KeyCode == BackwardMoveKey then
- backwardMove =0
- end
- if input.KeyCode == LeftMoveKey then
- leftMove = 0
- end
- if input.KeyCode == RightMoveKey then
- rightMove = 0
- end
- if input.KeyCode == UpMoveKey then
- upMove = 0
- end
- if input.KeyCode == DownMoveKey then
- downMove = 0
- end
- if input.KeyCode == MoreSpeedKey then
- aumentSpeed = false
- moveSpeed = minSpeed
- end
- end
- end)
- local runServiceHeartbeatSignal = game:GetService("RunService").Heartbeat:Connect(function(deltaTime:number)
- if isCamera then
- userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
- character.PrimaryPart.CFrame = CFrame.new(0,1200,0)
- character.PrimaryPart.AssemblyLinearVelocity = Vector3.new()
- local rotationCFrameTarget = CFrame.fromOrientation((currentCameraRotation.X), (currentCameraRotation.Y), (currentCameraRotation.Z))+currentCamera.CFrame.Position
- currentCamera.CFrame = rotationCFrameTarget
- currentCamera.CFrame = currentCamera.CFrame + (currentCamera.CFrame.LookVector * forwardMove * deltaTime)
- currentCamera.CFrame = currentCamera.CFrame - (currentCamera.CFrame.LookVector * backwardMove * deltaTime)
- currentCamera.CFrame = currentCamera.CFrame + (currentCamera.CFrame.RightVector * rightMove * deltaTime)
- currentCamera.CFrame = currentCamera.CFrame - (currentCamera.CFrame.RightVector * leftMove * deltaTime)
- currentCamera.CFrame = currentCamera.CFrame + Vector3.new(0, upMove * deltaTime, 0)
- currentCamera.CFrame = currentCamera.CFrame - Vector3.new(0, downMove * deltaTime, 0)
- if forwardMove > 0 then
- forwardMove = moveSpeed
- end
- if backwardMove > 0 then
- backwardMove = moveSpeed
- end
- if rightMove > 0 then
- rightMove = moveSpeed
- end
- if leftMove > 0 then
- leftMove = moveSpeed
- end
- if downMove > 0 then
- downMove = moveSpeed
- end
- if upMove > 0 then
- upMove = moveSpeed
- end
- moveSpeed = math.clamp(moveSpeed, minSpeed, maxSpeed)
- if aumentSpeed then
- moveSpeed += deltaTime * (acceleration*100)
- end
- end
- end)
- local function mouseMoved(actionName, inputState, inputObject:InputObject)
- local horizontalSpeed = inputObject.Delta.X*0.5
- local verticalSpeed = inputObject.Delta.Y*0.5
- currentCameraRotation += Vector3.new(math.clamp(-math.rad(verticalSpeed) * userInputService.MouseDeltaSensitivity, math.rad(-90), math.rad(90)), 0, 0)
- currentCameraRotation += Vector3.new(0, -math.rad(horizontalSpeed) * userInputService.MouseDeltaSensitivity, 0)
- currentCameraRotation = Vector3.new(math.clamp(currentCameraRotation.X, math.rad(-90), math.rad(90)), currentCameraRotation.Y, 0)
- end
- game:GetService("ContextActionService"):BindAction("MouseMoved", mouseMoved, false, Enum.UserInputType.MouseMovement)
- humanoid.Died:Connect(function()
- inputBeganSignal:Disconnect()
- inputEndedsignal:Disconnect()
- runServiceHeartbeatSignal:Disconnect()
- SetPartsAnchoredValue(false)
- isAnchored = false
- character.PrimaryPart.CFrame = currentCamera.CFrame
- humanoid.WalkSpeed = humanoidWalkSpeed
- userInputService.MouseBehavior = Enum.MouseBehavior.Default
- currentCamera.CameraType = Enum.CameraType.Custom
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement