Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Camera = workspace.CurrentCamera
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local Player = game.Players.LocalPlayer
- local Mouse = Player:GetMouse();
- local Character = Player.Character or Player.CharacterAdded:wait()
- -- Settings
- local MinCamGroundDistance = 20;
- local MaxCamGroundDistance = 70;
- local KeysHeld = {};
- local CamMovementTimeFactor = 1;
- -- Wait for the entire character to load.
- while (Character.Parent ~= workspace) do
- wait(0)
- end
- Character:WaitForChild("Head")
- Character:WaitForChild("Left Arm")
- Character:WaitForChild("Right Arm")
- Character:WaitForChild("Torso")
- Character:WaitForChild("Humanoid")
- Character:WaitForChild("Right Leg")
- Character:WaitForChild("Left Leg")
- Character:Destroy();
- Camera.CameraType = Enum.CameraType.Scriptable
- function DefaultRotation()
- local Position = Camera.CoordinateFrame.p
- local RayCheck = Ray.new(Position, Vector3.new(0,-1,0) * 300);
- local HitPart, HitPosition = workspace:FindPartOnRay(RayCheck)
- if (HitPart) then
- local DistanceToGround = (HitPosition - Position).magnitude
- if (DistanceToGround < MinCamGroundDistance) then
- Position = Position + Vector3.new(0, MinCamGroundDistance - DistanceToGround,0);
- elseif (DistanceToGround > MaxCamGroundDistance) then
- Position = Position - Vector3.new(0, DistanceToGround - MaxCamGroundDistance,0);
- end
- end
- Camera.CoordinateFrame = CFrame.new(Position) * CFrame.fromAxisAngle( Vector3.new(1,0,0), -math.pi/4)
- end
- DefaultRotation();
- Mouse.KeyDown:connect(function(Key)
- KeysHeld[Key:byte()] = true;
- print(Key:byte());
- end)
- Mouse.KeyUp:connect(function(Key)
- KeysHeld[Key:byte()] = false;
- end)
- RunService.RenderStepped:connect(function()
- local CamAdjustment = Vector3.new(0,0,0);
- if (KeysHeld[119]) then
- -- 'w' is held
- local Forward = Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(0,0,-1));
- local AdjustedVector = Vector3.new(Forward.X,0,Forward.Z);
- CamAdjustment = CamAdjustment + AdjustedVector
- end
- if (KeysHeld[97]) then
- -- 'a' is held
- local Left = Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(-1,0,0));
- local AdjustedVector = Vector3.new(Left.X,0,Left.Z);
- CamAdjustment = CamAdjustment + AdjustedVector
- end
- if (KeysHeld[115]) then
- -- 's' is held
- local Backward = Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(0,0,1));
- local AdjustedVector = Vector3.new(Backward.X,0,Backward.Z);
- CamAdjustment = CamAdjustment + AdjustedVector
- end
- if (KeysHeld[100]) then
- -- 'd' is held
- local Right = Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(1,0,0));
- local AdjustedVector = Vector3.new(Right.X,0,Right.Z);
- CamAdjustment = CamAdjustment + AdjustedVector
- end
- if (KeysHeld[113]) then
- -- 'q' is held
- Camera.CoordinateFrame = Camera.CoordinateFrame * CFrame.fromAxisAngle(Vector3.new(0,-1,0), math.rad(1))
- end
- if (KeysHeld[101]) then
- -- 'e' is held
- Camera.CoordinateFrame = Camera.CoordinateFrame * CFrame.fromAxisAngle(Vector3.new(0,1,0), math.rad(1))
- end
- Camera.CoordinateFrame = Camera.CoordinateFrame + CamAdjustment
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement