-
What do you want to achieve?
What I am trying to achieve is a camera system similar to the game Centura (A war game). See attached video below. Any help will be greatly appreciated as for I am a rookie to scripting and have used a script made by somebody else. Thank you for your time.
-
What is the issue?
The only issue is that if you rotate too fast while in a side view, the character looks like it is lagging. The video below shows what I currently have developed.
-
What solutions have you tried so far?
I have tired doing a while loop but that only made it worse, I have no clue how to fix it. It is probably rotating odd because it is a side view and not centered, I have no idea how to make it better.
this is my code (well not really, I modified somebody else’s code)
--Local script in StarterPlayerCharacter
--Services:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
--Variables:
local plr = game:GetService("Players").LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local root = hum.RootPart -- The HumanoidRootPart
local shiftlockenabled = -1 --negative values mean disabled
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.RightControl then
shiftlockenabled = shiftlockenabled * -1
if shiftlockenabled == -1 then
shiftLock(true)-- shiftlock on
elseif shiftlockenabled == 1 then
shiftLock(false)--shiftlock off
end
end
end)
--Toggle Function:
function shiftLock(active) --Toggle shift.lock function
if active then
hum.CameraOffset = Vector3.new(1.75,0,0) -- I assume this is about the right camera offset.
hum.AutoRotate = false --Disable the automatic rotation since we are the ones setting it.
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Set the mouse to center every frame.
local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ() --Get the angles of the camera
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0) --Set the root part to the camera's rotation
end)
else
RunService:UnbindFromRenderStep("ShiftLock") -- Allow mouse to move freely.
UserInputService.MouseBehavior = Enum.MouseBehavior.Default -- Let the mouse move freely
hum.AutoRotate = true --Let the humanoid handle the camera rotations again.
end
end
--Disable and Enable:
shiftLock(true) -- Toggle shift lock
--[[
shiftLock(false) --Toggle off shift Lock
]]
Thanks!