Created
March 18, 2017 03:13
-
-
Save Validark/c7dd2d6097d8183046349ad02ddd13df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @author Validark | |
-- @author CraneFly | |
-- @filtering Client-Side | |
-- This should go in StarterCharacterScripts | |
-- Localizations | |
local pi = math.pi | |
local atan2 = math.atan2 | |
local newCFrame = CFrame.new | |
local newCFrameAngles = CFrame.Angles | |
-- Services | |
local Players = game:GetService("Players") | |
local RunService = game:GetService("RunService") | |
-- Data | |
local Player = Players.LocalPlayer | |
local Mouse = Player:GetMouse() | |
local Camera = workspace.CurrentCamera | |
local Character = Player.Character or Player.CharacterAdded:Wait() | |
local Humanoid = Character:WaitForChild("Humanoid") | |
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") | |
-- Settings | |
Humanoid.WalkSpeed = 30 | |
Mouse.TargetFilter = workspace:FindFirstChild("Level") | |
Camera.FieldOfView = script:FindFirstChild("Fov") and script.Fov.Value or 70 | |
Player.AutoJumpEnabled = false | |
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) | |
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true) | |
-- Offset Values | |
local Empty = Vector3.new() | |
local _40 = Vector3.new(40, 40, 40) | |
local Offset = Empty | |
local function RenderStepped() | |
if HumanoidRootPart then -- Don"t run once HumanoidRootPart is removed | |
-- Rotate Character to Face mouse | |
local HumanoidRootPartPos = HumanoidRootPart.Position | |
local Dir = (Mouse.Hit.p - HumanoidRootPartPos).unit | |
HumanoidRootPart.CFrame = newCFrameAngles(0, atan2(Dir.X, Dir.Z) + pi, 0) + HumanoidRootPartPos | |
Camera.CoordinateFrame = newCFrame(HumanoidRootPartPos + Offset, HumanoidRootPartPos) | |
end | |
-- local PlayerPosition = Character.Head.Position | |
-- Camera.CoordinateFrame = newCFrame(PlayerPosition + Offset, PlayerPosition) | |
end | |
RunService.RenderStepped:Connect(RenderStepped) | |
--RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, RenderStepped) | |
Humanoid.FreeFalling:Connect(function() | |
Player.CameraMode = Enum.CameraMode.LockFirstPerson | |
Offset = Empty | |
print("FreeFalling") | |
end) | |
Humanoid.StateChanged:Connect(function(Old, New) | |
-- This runs whenever the Humanoid"s State changes | |
print(Old, New) | |
if Old ~= Enum.HumanoidStateType.Freefall then | |
Player.CameraMode = Enum.CameraMode.Classic | |
Offset = _40 | |
print("done2") | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment