jombo091

Realistic walk R6

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