Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Have the Camera Follow The Mouse? How would I do that?

Asked by 5 years ago
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()

local MaxXAxis1 = 0
local MaxXAxis2 = 1919

local Head = Character:WaitForChild("Head")

repeat 
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable


local function UpdateCam(inputType, gps)
    if not gps and inputType.UserInputType == Enum.UserInputType.MouseMovement then
        if inputType.Position.X >= MaxXAxis1 and inputType.Position.X <= MaxXAxis2 then
            print("\tPosition:",inputType.Position)
            Camera:Interpolate(Head.CFrame, Mouse.Hit, .1)
        end
    end
end

UIS.InputChanged:Connect(UpdateCam)

I'm trying to basically have the camera follow the mouse a bit, like seen in Menu GUI's, are you guys aware of anyway I could achieve this? I've tried interpolating the camera but this is glitchy and doesn't happen the way I want it to, any help?

0
Why are you looping at line 12 to change the CameraType? no loop needed User#19524 175 — 5y
0
Sometimes it does not set the CameraType so I do this as a failsafe. SuedeGod -5 — 5y
0
Wouldn't the repeat loop also pose a risk for crashing as there's no yield? Lugical 425 — 5y
0
no, not really as it only does this until the CameraType gets set to Scriptable, sometimes the script may run before the player spawns in hence the repeat loop until it is set SuedeGod -5 — 5y
View all comments (4 more)
0
Maybe create function that tracks the mouse as it moves, using the center of the screen as a reference. Connect the function to renderstep to update every frame ABK2017 406 — 5y
0
I heard of this magical setting called First Person Zripple 18 — 5y
0
First Person isn't doing it the way I want to though. SuedeGod -5 — 5y
0
is the camera anchored to a point or is it free(as if it can move around freely)? the8bitdude11 358 — 5y

Answer this question