Advertisement
Kchemerisov

awesome walk

Jul 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. --- Alot of people asked me a new version in R15
  2. --- So here it is ! some glitch is here but i'll fix it give me some time
  3. wait(2)
  4. local InputService=game:GetService("UserInputService")
  5. local Camera=game.Workspace.CurrentCamera
  6. local Player=game.Players.LocalPlayer
  7. local Character=Player.Character
  8. local Head=Character.Head
  9. local Torso=Character.LowerTorso
  10. local RootPart=Character.HumanoidRootPart
  11. local RootJoint=Head
  12. local Neck = Head.Neck
  13. Camera.FieldOfView=90
  14. Camera.CameraType="Scriptable"
  15. InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
  16.  
  17.  
  18.  
  19. local v3=Vector3.new
  20. local cf=CFrame.new
  21. local components=cf().components
  22. local inverse=cf().inverse
  23. local fromAxisAngle=CFrame.fromAxisAngle
  24. local atan,atan2=math.atan,math.atan2
  25. local acos=math.acos
  26.  
  27. local function toAxisAngleFromVector(v)
  28.     local z=v.z
  29.     return z*z<0.99999 and v3(v.y,-v.x,0).unit*acos(-z) or v3()
  30. end
  31.  
  32. local function AxisAngleLookOrientation(c,v,t)--CFrame,Vector,Tween
  33.     local c=c-c.p
  34.     local rv=(inverse(c)*v).unit
  35.     local rz=rv.z
  36.     return rz*rz<0.99999 and c*fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or c
  37. end
  38.  
  39. local function AxisAngleLookNew(v,t)--CFrame,Vector,Tween
  40.     local rv=v.unit
  41.     local rz=rv.z
  42.     return rz*rz<0.99999 and fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or cf()
  43. end
  44.  
  45. local function AxisAngleLook(c,v,t)--CFrame,Vector,Tween
  46.     local rv=(inverse(c)*v).unit
  47.     local rz=rv.z
  48.     return rz*rz<0.99999 and c*fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or c
  49. end
  50.  
  51.  
  52.  
  53.  
  54. local Sensitivity=0.005
  55.  
  56.  
  57. local CameraDirection=Vector3.new(0,0,1)
  58.  
  59. local function EulerAnglesYX(l)
  60.     local x,z=l.x,l.z
  61.     return atan(l.y/(x*x+z*z)^0.5),-atan2(x,-z)
  62. end
  63.  
  64. local function AnglesXY(l)
  65.     local z=l.z
  66.     return atan2(l.y,-z),-atan2(l.x,-z)
  67. end
  68.  
  69. local function MouseMoved(Input)
  70.     if Input.UserInputType==Enum.UserInputType.MouseMovement then
  71.         local dx,dy=Input.Delta.x*Sensitivity,Input.Delta.y*Sensitivity
  72.         local m2=dx*dx+dy*dy
  73.         if m2>0 then
  74.             CameraDirection=(AxisAngleLookOrientation(RootPart.CFrame,CameraDirection)*fromAxisAngle(v3(-dy,-dx,0),m2^0.5)).lookVector
  75.         end
  76.         local RootOrientation=RootPart.CFrame-RootPart.Position
  77.         local RelativeDirection=RootOrientation:inverse()*CameraDirection
  78.         local AngX,AngY=AnglesXY(RelativeDirection)--RootOrientation:inverse()*
  79.         if AngX<-1.57*11/12 then
  80.             local y,z,c,s=RelativeDirection.y,RelativeDirection.z,math.cos(-1.57*11/12-AngX),-math.sin(-1.57*11/12-AngX)
  81.             z,y=z*c-y*s,z*s+y*c
  82.             CameraDirection=RootOrientation*v3(RelativeDirection.x<0 and -(1-y*y-z*z)^0.5 or (1-y*y-z*z)^0.5,y,z)
  83.         elseif AngX>1.57*11/12 then
  84.             local y,z,c,s=RelativeDirection.y,RelativeDirection.z,math.cos(1.57*11/12-AngX),-math.sin(1.57*11/12-AngX)
  85.             z,y=z*c-y*s,z*s+y*c
  86.             CameraDirection=RootOrientation*v3(RelativeDirection.x<0 and -(1-y*y-z*z)^0.5 or (1-y*y-z*z)^0.5,y,z)
  87.         end
  88.     end
  89. end
  90.  
  91. local Mouse=Player:GetMouse()
  92.  
  93. local Zoom=-0.5
  94.  
  95. Mouse.KeyDown:connect(function(k)
  96.     if k=="e" then  
  97.         Zoom=-0.5
  98.     elseif k=="q" then
  99.         Zoom=-0.5
  100.     end
  101. end)
  102.  
  103. InputService.InputChanged:connect(MouseMoved)
  104.  
  105. Neck.C1=cf()
  106.  
  107. local _
  108. local DirectionBound=3.14159/3
  109. local CurrentAngY=0
  110.  
  111. local function CameraUpdate()
  112.     Camera.CameraType="Scriptable"
  113.     local cx,cz=CameraDirection.x,CameraDirection.z
  114.     local rvx,rvz=RootPart.Velocity.x,RootPart.Velocity.z
  115.     if rvx*rvx+rvz*rvz>4 and cx*rvx+cz*rvz<-0.5*(cx*cx+cz*cz)^0.5*(rvx*rvx+rvz*rvz)^0.5 then
  116.         DirectionBound=math.min(DirectionBound*0.9,math.abs(CurrentAngY*0.9))
  117.     else
  118.         DirectionBound=DirectionBound*0.1+3.14159/3*0.9
  119.     end
  120.     local AngX,AngY=EulerAnglesYX((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection)
  121.     if AngY>DirectionBound then
  122.         RootPart.CFrame=RootPart.CFrame*CFrame.Angles(0,AngY-DirectionBound,0)
  123.     elseif AngY<-DirectionBound then
  124.         RootPart.CFrame=RootPart.CFrame*CFrame.Angles(0,AngY+DirectionBound,0)
  125.     end
  126.     _,CurrentAngY=EulerAnglesYX((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection)
  127.     local CameraOrientation=AxisAngleLookNew((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection,1)
  128.     Neck.C0=CFrame.new(0,1,0)*CameraOrientation*CFrame.new(0,0.5,0)
  129.     local PreCam=AxisAngleLook(RootPart.CFrame*cf(0,1,0),RootPart.CFrame*v3(0,1,0)+CameraDirection)*CFrame.new(0,0.825,0)
  130.     if Zoom==8 then
  131.         local Part,Position=Workspace:findPartOnRay(Ray.new(PreCam.p,PreCam.lookVector*-8),Character)
  132.         Camera.CoordinateFrame=PreCam*CFrame.new(0,0,(Position-PreCam.p).magnitude)
  133.     else
  134.         Camera.CoordinateFrame=PreCam*CFrame.new(0,0,Zoom)
  135.     end
  136. end
  137.  
  138. game:GetService("RunService").RenderStepped:connect(CameraUpdate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement