Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local UP_VECTOR = Vector3.new(0, 1, 0)
- local XZ_VECTOR = Vector3.new(1, 0, 1) *
- local cameraSubject = camera and camera.CameraSubject
- local function IsFinite(num)
- return num == num and num ~= 1/0 and num ~= -1/0
- end
- local function IsFiniteVector3(vec3)
- return IsFinite(vec3.x) and IsFinite(vec3.y) and IsFinite(vec3.z)
- end
- function this:GetSubjectPosition()
- local result = nil
- local camera = workspace.CurrentCamera
- local cameraSubject = camera and camera.CameraSubject
- if cameraSubject then
- if cameraSubject:IsA('Humanoid') then
- local humanoidStateType = cameraSubject:GetState()
- if VRService.VREnabled and humanoidStateType == STATE_DEAD and cameraSubject == this.lastSubject then
- result = this.lastSubjectPosition
- else
- local humanoidRootPart = getHumanoidPartToFollow(cameraSubject, humanoidStateType)
- if humanoidRootPart and humanoidRootPart:IsA('BasePart') then
- local subjectCFrame = GetRenderCFrame(humanoidRootPart)
- local heightOffset = ZERO_VECTOR3
- if humanoidStateType ~= STATE_DEAD then
- heightOffset = cameraSubject.RigType == Enum.HumanoidRigType.R15 and R15HeadHeight or HEAD_OFFSET
- end
- if PortraitMode then
- heightOffset = heightOffset + Vector3.new(0, PORTRAIT_MODE_CAMERA_OFFSET, 0)
- end
- result = subjectCFrame.p +
- subjectCFrame:vectorToWorldSpace(heightOffset + cameraSubject.CameraOffset)
- end
- end
- elseif cameraSubject:IsA('VehicleSeat') then
- local subjectCFrame = GetRenderCFrame(cameraSubject)
- local offset = SEAT_OFFSET
- if VRService.VREnabled then
- offset = VR_SEAT_OFFSET
- end
- result = subjectCFrame.p + subjectCFrame:vectorToWorldSpace(offset)
- elseif cameraSubject:IsA('SkateboardPlatform') then
- local subjectCFrame = GetRenderCFrame(cameraSubject)
- result = subjectCFrame.p + SEAT_OFFSET
- elseif cameraSubject:IsA('BasePart') then
- local subjectCFrame = GetRenderCFrame(cameraSubject)
- result = subjectCFrame.p
- elseif cameraSubject:IsA('Model') then
- result = cameraSubject:GetModelCFrame().p
- end
- end
- this.lastSubject = cameraSubject
- this.lastSubjectPosition = result
- return result
- end
- function this:RotateCamera(startLook, xyRotateVector)
- if VRService.VREnabled then
- local yawRotatedVector, xyRotateVector = self:RotateVector(startLook, Vector2.new(xyRotateVector.x, 0))
- return Vector3_new(yawRotatedVector.x, 0, yawRotatedVector.z).unit, xyRotateVector
- else
- local startVertical = math_asin(startLook.y)
- local yTheta = clamp(-MAX_Y + startVertical, -MIN_Y + startVertical, xyRotateVector.y)
- return self:RotateVector(startLook, Vector2_new(xyRotateVector.x, yTheta))
- end
- end
- function this:GetCameraLook()
- return workspace.CurrentCamera and workspace.CurrentCamera.CoordinateFrame.lookVector or Vector3.new(0,0,1)
- end
- -- idk rotateinput
- if self:GetShiftLock() and not self:IsInFirstPerson() then
- -- We need to use the right vector of the camera after rotation, not before
- local newLookVector = self:RotateCamera(self:GetCameraLook(), self.RotateInput)
- local offset = ((newLookVector * XZ_VECTOR):Cross(UP_VECTOR).unit * 1.75)
- if IsFiniteVector3(offset) then
- subjectPosition = subjectPosition + offset
- end
- else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement