I am making a Battle Royale game and I do not know how to script the camera like what it does in Island Royale.
COMMUNITY QUESTION
How do I make the Third Person Camera and my Character face towards the crosshair?
1 answer
place in StarterPack; i will explain everything below
local rs = game:GetService("RunService")
local uip = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local angX = 0
local angY = 0
local camPos = Vector3.new(3.5, 0, 7.5)
wait(.1)
cam.CameraType = Enum.CameraType.Scriptable
uip.MouseBehavior = Enum.MouseBehavior.LockCenter
uip.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
angX = angX - input.Delta.X * .4
angY = math.clamp(angY - input.Delta.Y * .4, -80, 80)
end
end)
rs.RenderStepped:Connect(function()
local char = plr.Character
local root = char:FindFirstChild("HumanoidRootPart")
local waist = char:FindFirstChild("Waist", true)
local neck = char:FindFirstChild("Neck", true)
if char and root then
local dir = (root.CFrame:Inverse() * cam.CFrame).LookVector
root.CFrame = root.CFrame * CFrame.Angles(0, -math.asin(dir.X), 0)
waist.C1 = CFrame.new(waist.C1.p) * CFrame.Angles(-math.asin(dir.Y) / 2, math.asin(dir.X) / 2, 0)
neck.C1 = CFrame.new(neck.C1.p) * CFrame.Angles(-math.asin(dir.Y) / 2, math.asin(dir.X) / 2, 0)
local startCFrame = CFrame.new((root.Position + Vector3.new(0, 2, 0))) * CFrame.Angles(0, math.rad(angX), 0) * CFrame.Angles(math.rad(angY), 0, 0)
local camCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(camPos.X, camPos.Y, camPos.Z))
local camFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(camPos.X, camPos.Y, -99999))
cam.CFrame = CFrame.new(camCFrame.p, camFocus.p)
end
end)
so what dis does in essence is lock the mouse at the center, constantly offset the camera's position while making the player turn on the X axis to face the mouse and I added some dynamics to the character's stale body.
3 comments
0
What if the player is on mobile?
0
i have made it so that the player faces the camera, instead of following the mouse.
0
this should hopefully solve that problem
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
shift lock
not a request site