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

How to turn character to mouse movement for third person camera?

Asked by 10 years ago

If you put this in a local script, the camera locks to the user.

My question is, how do I simulate the character turning like when you have Mouse Shift lock enabled, and how do I fix the camera glitch when the player backs up?

while not game.Players.LocalPlayer do wait() end
player = game.Players.LocalPlayer
while not player.Character do wait() end
character = player.Character
while not character:FindFirstChild("Head") do wait() end
head = character.Head
while not workspace.CurrentCamera do wait() end
camera = workspace.CurrentCamera
while not player:GetMouse() do wait() end
mouse = player:GetMouse()

camera.CameraType = "Scriptable"
camera.FieldOfView = 70

target = head

input = game:GetService("UserInputService")
input.MouseBehavior = Enum.MouseBehavior.LockCenter

game:GetService("RunService").RenderStepped:connect(function()
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CoordinateFrame = target.CFrame * CFrame.new(16,6,20)
end)

Answer this question