Advertisement
StefanBashkir

Custom Cam

Feb 26th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local zoom = (-30)
  2. local yshift = 5
  3.  
  4. -- LocalScript instance inside the StarterGui
  5. local c = Workspace.CurrentCamera
  6. local p = Game.Players.LocalPlayer
  7. repeat wait() until p.Character;
  8. wait(1)
  9. local char = p.Character
  10. local s = Game:GetService("RunService");
  11. local m = p:GetMouse();
  12.  
  13. -- settings
  14. c.CameraType = "Scriptable"
  15. local directlybehind = char.Head.Position + Vector3.new(0,0,zoom) --+ (char.Torso.CFrame.lookVector * -10)
  16. local originalDirection = CFrame.new(directlybehind, char.Head.Position).lookVector
  17. local direction = originalDirection * 1e50
  18. local shift = --[[char.Torso.CFrame:vectorToWorldSpace(Vector3.new(6,0,0))]] Vector3.new(0,yshift,0);
  19. local lastY = c.CoordinateFrame.p.y;
  20. local isJumping = false;
  21. --[[
  22. char.Humanoid.Changed:connect(function(prop)
  23.     if prop == "Jump" then
  24.         isJumping = true;
  25.         coroutine.wrap(function()
  26.             wait(2)
  27.             isJumping = false;
  28.         end)()
  29.     end
  30. end)]]
  31.  
  32. function GetDistanceToFloor()
  33.     local r = Ray.new(char.Head.Position, Vector3.new(0,-500,0));
  34.     local part,point = Workspace:FindPartOnRay(r, char)
  35.     if point then
  36.         return (char.Head.Position - point).magnitude
  37.     end
  38.     return 5
  39. end
  40.  
  41. -- while loop to set camera coordinate frame
  42. s.RenderStepped:connect(function()
  43.     if GetDistanceToFloor() < 4.6 then -- touching a floor (actual value is 4.5)
  44.         directlybehind = char.Head.Position + Vector3.new(0,0,zoom)
  45.         lastY = c.CoordinateFrame.p.y
  46.     else
  47.         directlybehind = Vector3.new(char.Head.Position.X, lastY, char.Head.Position.Z) + Vector3.new(0,0,zoom)
  48.     end
  49.     c.CoordinateFrame = CFrame.new(directlybehind + shift, char.Head.Position);
  50. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement