So I have set my CameraSubject to the head of the character, but shiftlock does not work with this. The effect I wanna have does not happen and instead is frozen rotation when in shiftlock. How do I make this work?
One way to do this is to use the CFrame.lookAt() function to update the character’s orientation to match the camera’s orientation.
Try this code:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local shiftLockEnabled = false
camera.CameraSubject = character:WaitForChild("Head")
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockEnabled = true
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockEnabled = false
end
end)
-- Update the character's orientation to match the camera's orientation when shiftlock is enabled
game:GetService("RunService").Stepped:Connect(function()
if shiftLockEnabled then
local lookVector = camera.CFrame.lookVector
lookVector = Vector3.new(lookVector.X, 0, lookVector.Z).Unit
local newCFrame = CFrame.lookAt(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + lookVector, Vector3.new(0, 1, 0))
character.HumanoidRootPart.CFrame = newCFrame
end
end)
this does work but it disables right after letting go of shift, and in my game, you will also have times where you are not supposed to rotate your character. will this effect that?
The script I provided might affect those areas where you are not suppose to rotate your character but to ensure appropriate character rotation in your game, you may need to add checks based on your game mechanics and level design. This can help prevent unintended rotation in certain areas or situations.
This code should work in any LocalScript placed in the game, but you’ll need to ensure it’s not conflicting with any other camera or input-related scripts.
You can add this code to a new LocalScript and place it under the:
StarterPlayer > StarterCharacterScripts or StarterPlayer > StarterPlayerScripts
This will ensure the code is run whenever a new character is spawned, or the player joins the game.
no i meant as in effecting the default roblox modules for camera handling, roblox does not give you the default CameraScript code so i don’t know if i’m just saying impossible things.
As for fixing the rotation disabling while shiftlock is still active, try this edited version of Array’s script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local shiftLockEnabled = false
camera.CameraSubject = character:WaitForChild("Head")
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockEnabled = not shiftLockEnabled
end
end)
-- Update the character's orientation to match the camera's orientation when shiftlock is enabled
game:GetService("RunService").Stepped:Connect(function()
if shiftLockEnabled then
local lookVector = camera.CFrame.lookVector
lookVector = Vector3.new(lookVector.X, 0, lookVector.Z).Unit
local newCFrame = CFrame.lookAt(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + lookVector, Vector3.new(0, 1, 0))
character.HumanoidRootPart.CFrame = newCFrame
end
end)
I know im late, but you can use this script, insert it in StarterCharacterScripts
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
local hrp = character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local runService = game:GetService("RunService")
camera.CameraSubject = character:WaitForChild("Head")
runService.RenderStepped:Connect(function()
if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
hrp.CFrame = CFrame.lookAt(hrp.Position, hrp.Position + Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z))
end
end)
Yeah it really is, i found another alternative though. Instead of using this, which is TERRIBLE for performance, you can use this script instead.
OH YEAH, dont use camera subject, this script changes the camera offset depending on the heads position.
task.wait(1.5)
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local rootpart, head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function()
game:GetService("TweenService"):Create(hum,TweenInfo.new(0.3),{CameraOffset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)}):Play()
end)