Custom Shiftlock

Hey I am making a custom shift lock and I was wondering how to fix the choppiness when the character is rotating

plr.Character.PrimaryPart.CFrame = CFrame.new(plr.Character.PrimaryPart.CFrame.p, plr.Character.PrimaryPart.CFrame.p + Vector3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))
6 Likes

Try something like this…

local shiftLockSmoothSpeed = 10
local targetRotation = CFrame.new(plr.Character.PrimaryPart.CFrame.p, plr.Character.PrimaryPart.CFrame.p + Vector3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))

game:GetService("RunService").Heartbeat:Connect(function()
    local currentCFrame = plr.Character.PrimaryPart.CFrame
    local newRotation = currentCFrame:Lerp(targetRotation, shiftLockSmoothSpeed * game:GetService("RunService").Heartbeat:Wait())
    plr.Character.PrimaryPart.CFrame = CFrame.new(currentCFrame.p, newRotation.p + newRotation.LookVector)
end)

Using the runService automatically makes it even smoother, just set the smoothspeed to your liking.

2 Likes

Are you using RunService? Or something else?

I would recommend lerping for just a little smoother animation that might fix your choppiness.

Would be helpful if you provided the whole snippet, thank you.

1 Like

Now I cant move just rotate

game:GetService("RunService"):BindToRenderStep("CameraOffset", Enum.RenderPriority.Camera.Value - 1, function()
	if plr.Character then
		local offset = Vector3.new(C.CurrentXOffset.Value, 0, 0)
		TS:Create(plr.Character.Humanoid, TweenInfo.new(.1), {CameraOffset = offset}):Play()
		--plr.Character.Humanoid.CameraOffset = offset
		if C.ShiftLock == true then
			local currentCFrame = plr.Character.PrimaryPart.CFrame
			local targetCFrame = CFrame.new(plr.Character.PrimaryPart.CFrame.p, plr.Character.PrimaryPart.CFrame.p + Vector3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))
			local newRotation = currentCFrame:Lerp(targetCFrame, 10 * game:GetService("RunService").Heartbeat:Wait())
			plr.Character.PrimaryPart.CFrame = CFrame.new(currentCFrame.p, newRotation.p + newRotation.LookVector)
		end
	end
end)
1 Like

Try this

game:GetService("RunService"):BindToRenderStep("CameraOffset", Enum.RenderPriority.Camera.Value - 1, function()
	if plr.Character and plr.Character:FindFirstChild("Humanoid") then
		local offset = Vector3.new(C.CurrentXOffset.Value, 0, 0)
		TS:Create(plr.Character.Humanoid, TweenInfo.new(.1), {CameraOffset = offset}):Play()

		if C.ShiftLock == true then
			local currentCFrame = plr.Character.PrimaryPart.CFrame
			local targetCFrame = CFrame.new(plr.Character.PrimaryPart.CFrame.p, plr.Character.PrimaryPart.CFrame.p + Vector3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))

			local newRotation = currentCFrame:Lerp(targetCFrame, 10 * game:GetService("RunService").Heartbeat:Wait())
			plr.Character.PrimaryPart.CFrame = CFrame.new(currentCFrame.p, newRotation.p + newRotation.LookVector)
		end
	end
end)

same issue

is it running in run service maybe try changing the render step priority. nvm

Here is a script from one of my old games, try this!

ServerScriptService

game:GetService("StarterPlayer").EnableMouseLockOption = false

StarterPlayerScripts
CustomShiftLock.rbxm (7.2 KB)

1 Like

It is already set to false (ignore)

Has this file worked out for you? (blabber,blabber,blabber,blabber,blabber,)

So I got something working, though I was editing it a ton for me to work in studio, so you will have to adjust it to your needs, anyway this is what I got:

local plr = game.Players.LocalPlayer
local currentCamera = workspace.CurrentCamera

game:GetService("RunService"):BindToRenderStep("CameraOffset", Enum.RenderPriority.Camera.Value - 1, function()
	if plr.Character then
		
		plr.Character.Humanoid.AutoRotate = false
		
		local offset = Vector3.new(1, 0, 0)
		
		plr.Character.Humanoid.CameraOffset = offset
			local currentCFrame = plr.Character.PrimaryPart.CFrame
			local targetCFrame = CFrame.new(plr.Character.PrimaryPart.CFrame.p, plr.Character.PrimaryPart.CFrame.p + Vector3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))
		local newRotation = currentCFrame:Lerp(targetCFrame, 10 * game:GetService("RunService").RenderStepped:Wait())
		plr.Character.PrimaryPart.CFrame = CFrame.new(plr.Character.PrimaryPart.Position, newRotation.p + newRotation.LookVector)
	end
end)

Just on a side note, the further you offset the camera from the player, the choppier it gets. So you might have to fix that as well, probably by speeding up the lerp might fix it, something around 10-30 works best imo.