Hi.
I have been scripting a code which will enable an OTS System over the shoulder, however whenever enabled it will set the mouse to a specific location instead of the location the HumanoidRootPart is facing.
ModuleScript, ScreenGUI/StarterGui
Camera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
-- local h = Character:WaitForChild("Humanoid") (this is defined earlier)
h.AutoRotate = false
local hrp = Character:WaitForChild("HumanoidRootPart")
local camAngleX = 0
local camAngleY = 0
local function i(ac, state, obj)
if state == Enum.UserInputState.Change then
camAngleX -= obj.Delta.X
camAngleY = math.clamp(camAngleY-obj.Delta.Y, -75, 75)
end
end
ContextActionService:BindAction("changed", i, false, Enum.UserInputType.MouseMovement)
RunService:BindToRenderStep("changed", Enum.RenderPriority.Camera.Value, function()
local sCFrame = CFrame.new(hrp.CFrame.Position) * CFrame.Angles(0,math.rad(camAngleX),0) * CFrame.Angles(math.rad(camAngleY),0,0)
local cCFrame = sCFrame:PointToWorldSpace(camOffset)
local camFocus = sCFrame:PointToWorldSpace(Vector3.new(camOffset.X, camOffset.Y, -10^6))
ts:Create(Camera, TweenInfo.new(camOffsetTime, Enum.EasingStyle.Linear), {CFrame = CFrame.lookAt(cCFrame, camFocus)}):Play()
local lookCFrame = CFrame.lookAt(hrp.Position, Camera.CFrame:PointToWorldSpace(Vector3.new(0,0,-10^6)))
hrp.CFrame = CFrame.fromMatrix(hrp.Position, lookCFrame.XVector, hrp.CFrame.YVector)
end)
Example Bug In Code (1.6 MB)