Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.28 KB | None | 0 0
  1. local UP_VECTOR = Vector3.new(0, 1, 0)
  2. local XZ_VECTOR = Vector3.new(1, 0, 1)      *
  3. local cameraSubject = camera and camera.CameraSubject
  4.  
  5. local function IsFinite(num)
  6.     return num == num and num ~= 1/0 and num ~= -1/0
  7. end
  8.  
  9. local function IsFiniteVector3(vec3)
  10.     return IsFinite(vec3.x) and IsFinite(vec3.y) and IsFinite(vec3.z)
  11. end
  12.  
  13.     function this:GetSubjectPosition()
  14.         local result = nil
  15.         local camera = workspace.CurrentCamera
  16.         local cameraSubject = camera and camera.CameraSubject
  17.         if cameraSubject then
  18.             if cameraSubject:IsA('Humanoid') then
  19.                 local humanoidStateType = cameraSubject:GetState()
  20.                 if VRService.VREnabled and humanoidStateType == STATE_DEAD and cameraSubject == this.lastSubject then
  21.                     result = this.lastSubjectPosition
  22.                 else
  23.                     local humanoidRootPart = getHumanoidPartToFollow(cameraSubject, humanoidStateType)
  24.                     if humanoidRootPart and humanoidRootPart:IsA('BasePart') then
  25.                         local subjectCFrame = GetRenderCFrame(humanoidRootPart)
  26.                         local heightOffset = ZERO_VECTOR3
  27.                         if humanoidStateType ~= STATE_DEAD then
  28.                             heightOffset = cameraSubject.RigType == Enum.HumanoidRigType.R15 and R15HeadHeight or HEAD_OFFSET
  29.                         end
  30.  
  31.                         if PortraitMode then
  32.                             heightOffset = heightOffset + Vector3.new(0, PORTRAIT_MODE_CAMERA_OFFSET, 0)
  33.                         end
  34.  
  35.                         result = subjectCFrame.p +
  36.                             subjectCFrame:vectorToWorldSpace(heightOffset + cameraSubject.CameraOffset)
  37.                     end
  38.                 end
  39.             elseif cameraSubject:IsA('VehicleSeat') then
  40.                 local subjectCFrame = GetRenderCFrame(cameraSubject)
  41.                 local offset = SEAT_OFFSET
  42.                 if VRService.VREnabled then
  43.                     offset = VR_SEAT_OFFSET
  44.                 end
  45.                 result = subjectCFrame.p + subjectCFrame:vectorToWorldSpace(offset)
  46.             elseif cameraSubject:IsA('SkateboardPlatform') then
  47.                 local subjectCFrame = GetRenderCFrame(cameraSubject)
  48.                 result = subjectCFrame.p + SEAT_OFFSET
  49.             elseif cameraSubject:IsA('BasePart') then
  50.                 local subjectCFrame = GetRenderCFrame(cameraSubject)
  51.                 result = subjectCFrame.p
  52.             elseif cameraSubject:IsA('Model') then
  53.                 result = cameraSubject:GetModelCFrame().p
  54.             end
  55.         end
  56.         this.lastSubject = cameraSubject
  57.         this.lastSubjectPosition = result
  58.         return result
  59.     end
  60.  
  61.     function this:RotateCamera(startLook, xyRotateVector)
  62.         if VRService.VREnabled then
  63.             local yawRotatedVector, xyRotateVector = self:RotateVector(startLook, Vector2.new(xyRotateVector.x, 0))
  64.             return Vector3_new(yawRotatedVector.x, 0, yawRotatedVector.z).unit, xyRotateVector
  65.         else
  66.             local startVertical = math_asin(startLook.y)
  67.             local yTheta = clamp(-MAX_Y + startVertical, -MIN_Y + startVertical, xyRotateVector.y)
  68.             return self:RotateVector(startLook, Vector2_new(xyRotateVector.x, yTheta))
  69.         end
  70.     end
  71.  
  72.     function this:GetCameraLook()
  73.         return workspace.CurrentCamera and workspace.CurrentCamera.CoordinateFrame.lookVector or Vector3.new(0,0,1)
  74.     end
  75.  
  76. -- idk rotateinput
  77.             if self:GetShiftLock() and not self:IsInFirstPerson() then
  78.                 -- We need to use the right vector of the camera after rotation, not before
  79.                 local newLookVector = self:RotateCamera(self:GetCameraLook(), self.RotateInput)
  80.                 local offset = ((newLookVector * XZ_VECTOR):Cross(UP_VECTOR).unit * 1.75)
  81.  
  82.                 if IsFiniteVector3(offset) then
  83.                     subjectPosition = subjectPosition + offset
  84.                 end
  85.             else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement