Advertisement
BobMe

VRM

Feb 19th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. wait(2)
  2.  
  3. local InputService=game:GetService("UserInputService")
  4. local Camera=game.Workspace.CurrentCamera
  5. local Player=game.Players.LocalPlayer
  6. local Character=Player.Character
  7. local Head=Character.Head
  8. local Torso=Character.Torso
  9. local RootPart=Character.HumanoidRootPart
  10. local RootJoint=RootPart.RootJoint
  11. local Neck=Torso.Neck
  12. Camera.FieldOfView=90
  13. Camera.CameraType="Scriptable"
  14. InputService.MouseBehavior=Enum.MouseBehavior.LockCenter
  15. port = Instance.new("Part", game.Players.LocalPlayer.Character)
  16. port.Transparency = 1
  17. port.CanCollide = false
  18. port.Anchored = true
  19. port.Name = ("parted")
  20.  
  21. local plr = game.Players.LocalPlayer
  22. plr.Changed:connect(function(change)
  23. if (change == "Character.parted") then
  24. plr.CameraMode = "Classic"
  25. script.Disabled = true
  26. script:Destroy()
  27. end
  28. end)
  29.  
  30.  
  31. local v3=Vector3.new
  32. local cf=CFrame.new
  33. local components=cf().components
  34. local inverse=cf().inverse
  35. local fromAxisAngle=CFrame.fromAxisAngle
  36. local atan,atan2=math.atan,math.atan2
  37. local acos=math.acos
  38.  
  39. local function toAxisAngleFromVector(v)
  40. local z=v.z
  41. return z*z<0.99999 and v3(v.y,-v.x,0).unit*acos(-z) or v3()
  42. end
  43.  
  44. local function AxisAngleLookOrientation(c,v,t)--CFrame,Vector,Tween
  45. local c=c-c.p
  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. local function AxisAngleLookNew(v,t)--CFrame,Vector,Tween
  52. local rv=v.unit
  53. local rz=rv.z
  54. return rz*rz<0.99999 and fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or cf()
  55. end
  56.  
  57. local function AxisAngleLook(c,v,t)--CFrame,Vector,Tween
  58. local rv=(inverse(c)*v).unit
  59. local rz=rv.z
  60. return rz*rz<0.99999 and c*fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or c
  61. end
  62.  
  63.  
  64.  
  65.  
  66. local Sensitivity=0.005
  67.  
  68.  
  69. local CameraDirection=Vector3.new(0,0,1)
  70.  
  71. local function EulerAnglesYX(l)
  72. local x,z=l.x,l.z
  73. return atan(l.y/(x*x+z*z)^0.5),-atan2(x,-z)
  74. end
  75.  
  76. local function AnglesXY(l)
  77. local z=l.z
  78. return atan2(l.y,-z),-atan2(l.x,-z)
  79. end
  80.  
  81. local function MouseMoved(Input)
  82. if Input.UserInputType==Enum.UserInputType.MouseMovement then
  83. local dx,dy=Input.Delta.x*Sensitivity,Input.Delta.y*Sensitivity
  84. local m2=dx*dx+dy*dy
  85. if m2>0 then
  86. CameraDirection=(AxisAngleLookOrientation(RootPart.CFrame,CameraDirection)*fromAxisAngle(v3(-dy,-dx,0),m2^0.5)).lookVector
  87. end
  88. local RootOrientation=RootPart.CFrame-RootPart.Position
  89. local RelativeDirection=RootOrientation:inverse()*CameraDirection
  90. local AngX,AngY=AnglesXY(RelativeDirection)--RootOrientation:inverse()*
  91. if AngX<-1.57*11/12 then
  92. local y,z,c,s=RelativeDirection.y,RelativeDirection.z,math.cos(-1.57*11/12-AngX),-math.sin(-1.57*11/12-AngX)
  93. z,y=z*c-y*s,z*s+y*c
  94. CameraDirection=RootOrientation*v3(RelativeDirection.x<0 and -(1-y*y-z*z)^0.5 or (1-y*y-z*z)^0.5,y,z)
  95. elseif AngX>1.57*11/12 then
  96. local y,z,c,s=RelativeDirection.y,RelativeDirection.z,math.cos(1.57*11/12-AngX),-math.sin(1.57*11/12-AngX)
  97. z,y=z*c-y*s,z*s+y*c
  98. CameraDirection=RootOrientation*v3(RelativeDirection.x<0 and -(1-y*y-z*z)^0.5 or (1-y*y-z*z)^0.5,y,z)
  99. end
  100. end
  101. end
  102.  
  103. local Mouse=Player:GetMouse()
  104.  
  105. local Zoom=-0.5
  106.  
  107. Mouse.KeyDown:connect(function(k)
  108. if k=="j" then
  109. Zoom=-0.5
  110. elseif k=="l" then
  111. Zoom=8
  112. end
  113. end)
  114.  
  115. InputService.InputChanged:connect(MouseMoved)
  116.  
  117. Neck.C1=cf()
  118.  
  119. local _
  120. local DirectionBound=3.14159/3
  121. local CurrentAngY=0
  122.  
  123. local function CameraUpdate()
  124. Camera.CameraType="Scriptable"
  125. local cx,cz=CameraDirection.x,CameraDirection.z
  126. local rvx,rvz=RootPart.Velocity.x,RootPart.Velocity.z
  127. 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
  128. DirectionBound=math.min(DirectionBound*0.9,math.abs(CurrentAngY*0.9))
  129. else
  130. DirectionBound=DirectionBound*0.1+3.14159/3*0.9
  131. end
  132. local AngX,AngY=EulerAnglesYX((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection)
  133. if AngY>DirectionBound then
  134. RootPart.CFrame=RootPart.CFrame*CFrame.Angles(0,AngY-DirectionBound,0)
  135. elseif AngY<-DirectionBound then
  136. RootPart.CFrame=RootPart.CFrame*CFrame.Angles(0,AngY+DirectionBound,0)
  137. end
  138. _,CurrentAngY=EulerAnglesYX((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection)
  139. local CameraOrientation=AxisAngleLookNew((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection,1)
  140. Neck.C0=CFrame.new(0,1,0)*CameraOrientation*CFrame.new(0,0.5,0)
  141. local PreCam=AxisAngleLook(RootPart.CFrame*cf(0,1,0),RootPart.CFrame*v3(0,1,0)+CameraDirection)*CFrame.new(0,0.825,0)
  142. if Zoom==8 then
  143. local Part,Position=Workspace:findPartOnRay(Ray.new(PreCam.p,PreCam.lookVector*-8),Character)
  144. Camera.CoordinateFrame=PreCam*CFrame.new(0,0,(Position-PreCam.p).magnitude)
  145. else
  146. Camera.CoordinateFrame=PreCam*CFrame.new(0,0,Zoom)
  147. end
  148. end
  149.  
  150. local d = game.Players.LocalPlayer.Character:GetChildren()
  151. for i=1, #d do
  152. if (d[i].className == "Accessory") then
  153. d[i].Handle.LocalTransparencyModifier = 1
  154. end
  155. end
  156. game.Workspace.Memo1332.EpicWings.Handle.LocalTransparencyModifier = 0
  157.  
  158. local plr = game.Players.LocalPlayer
  159. plr.Changed:connect(function(change)
  160. if (change == "Character.parted") then
  161. plr.CameraMode = "Classic"
  162. script.Disabled = true
  163. script:Destroy()
  164. end
  165. end)
  166.  
  167. plr.Character.parted.ChildRemoved:connect(function(partedoof)
  168. if partedoof then
  169. plr.CameraMode = "Classic"
  170. script.Disabled = true
  171. script:Destroy()
  172. end
  173. end)
  174.  
  175. game:GetService("RunService").RenderStepped:connect(CameraUpdate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement