Im making a gun system where third person and first person is needed, and if its in third person the player cursor needs to be centered and the camera needs to be offset to the right of the player (similar to shiftlock). I know how to center the cursor but how can i offset the camera on the right side of the player, while still ensuring first person still works the same?
1 Like
workspace.CurrentCamera.CFrame:ToWorldSpace(CFrame.new(-5, 0, 0));
Use this: ![]()
Humanoid.CameraOffset = Vector3.new(1.65, 0, 0.1) -- Adjust the vector value to your liking.
1 Like
It does work, but the weird side effect is that if the player moves back (pressing s) the player model would appear on the right side of the screen. Is there a way to imitate the roblox default shift lock or remap the key for the shift lock?
1 Like
I ripped this out of a game of mine and edited it for your use tell me if anything needs to be changed because I have not tested this just yet.
Put this in a local script in starterplayer. To enable shiftlock use Humanoid:SetAttribute(“MouseLock”, true) in another script.
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local TS = game:GetService("TweenService")
local Camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Humanoid:Humanoid = Player.Character:WaitForChild("Humanoid")
RS.Heartbeat:Connect(function()
if Humanoid.Health <= 0 then Humanoid:SetAttribute("MouseLock", false) end
if Humanoid:GetAttribute("MouseLock") then
local X, Y, Z = Camera.CFrame:ToOrientation()
TS:Create(Player.Character.HumanoidRootPart, TweenInfo.new(0.385, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position) * CFrame.Angles(0, Y, 0)}):Play()
end
end)
Humanoid:GetAttributeChangedSignal("MouseLock"):Connect(function()
local MouseLock = Humanoid:GetAttribute("MouseLock")
Humanoid.AutoRotate = not MouseLock
if MouseLock then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
Mouse.Icon = "rbxassetid://10546018744"
Humanoid.CameraOffset = Vector3.new(0.535, 0.0835, 0))
else
UIS.MouseBehavior = Enum.MouseBehavior.Default
Mouse.Icon = ""
Humanoid.CameraOffset = Vector3.new(0, 0, 0))
end
end)