#custom Shiftlock

1 messages · Page 1 of 1 (latest)

pearl raptor
#
local Input:UserInputService = game:GetService("UserInputService")
local RunService:RunService = game:GetService("RunService")
local TS:TweenService = game:GetService("TweenService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local rootpart = character.HumanoidRootPart

local indice = true

local TI = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In)


Input.InputBegan:Connect(function(input)

    if input.KeyCode == Enum.KeyCode.LeftControl then
        if indice == true then
            indice = false
            humanoid.AutoRotate = false
            Input.MouseDeltaSensitivity = 0.65
            Input.MouseBehavior = Enum.MouseBehavior.LockCenter

            local tween = TS:Create(humanoid, TI, {CameraOffset = Vector3.new(3, 0, 0)})
            tween:Play()

            RunService:BindToRenderStep("CamLock", 0, function()
                task.wait()
                local LV = workspace.CurrentCamera.CFrame.LookVector
                local flatLV = Vector3.new(LV.X, 0, LV.Z).Unit
                local GoalOrientation = CFrame.new(rootpart.Position, rootpart.Position + flatLV)
                
                rootpart.CFrame = rootpart.CFrame:Lerp(GoalOrientation, 0.4)
            end)
        else
            indice = true            
            humanoid.AutoRotate = true
            Input.MouseDeltaSensitivity = 1
            Input.MouseBehavior = Enum.MouseBehavior.Default

            local tween = TS:Create(humanoid, TI, {CameraOffset = Vector3.new(0, 0, 0)})
            tween:Play()

            RunService:UnbindFromRenderStep("CamLock")
        end
    end

end)
#

if i move slow it's not as noticeable, but if i move the camera too fast you can see the character jitter a little

#

picture version if it's easier for you to read

forest osprey
#

roblox already has a shiftlock

pearl raptor
#

i'm trying to make my own

#

so that it work when i press control instead

#

you can modify the key that trigger the lock

#
local Input:UserInputService = game:GetService("UserInputService")
local RunService:RunService = game:GetService("RunService")
local TS:TweenService = game:GetService("TweenService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local rootpart = character.HumanoidRootPart
RunService:BindToRenderStep("CamLock", 0, function()
                task.wait()
                local LV = workspace.CurrentCamera.CFrame.LookVector
                local flatLV = Vector3.new(LV.X, 0, LV.Z).Unit
                local GoalOrientation = CFrame.new(rootpart.Position, rootpart.Position + flatLV)
                
                rootpart.CFrame = rootpart.CFrame:Lerp(GoalOrientation, 0.4)
            end)

relevant variables on top and the code that does the custom shiftlock below

shut condor
#

what happens when you lower the time for the tween

pearl raptor
#

it would be too slow for my liking and still continues to jitter noticeably

#

ideally i'd like it to be almost instant but it would jitter way too much

#

so i gave up that idea and try to keep it somewhat fast

forest osprey
#

lerp it on renderstepped instead of tween

#

make sure its lerped client side

pearl raptor
#

i lerp it on RenderStep already, and yes it's a client script

forest osprey
#

hm

#

you lerp position or rotation?

#

and what part of the character do u lerp?

pearl raptor
#

i lerp the CFrame, but the Position doesn't change between starting and goal value

#

so it just lerp the orientation

forest osprey
#

have u tried lerping the character using PivotTo()

pearl raptor
#

doesn't this just move the character ?

forest osprey
#

no, it sets the cframe

pearl raptor
#

i'll try it

forest osprey
#

in fairness i havent read the code cos im on mobile so give me a couple mins and then i can acrually read it 😭

pearl raptor
#

alright

#

i tried PivotTo and it doesn't change much

forest osprey
#

hm

#

try lerp only rotation

pearl raptor
#

if you just modify the rotation you need euler angles

#

CFrame use 2 coordinates

#

and i get the orientation with a coordinate

visual rover
pearl raptor
#

hm i could still try using only rotation tho

#

since the camera have an orientation property

#

yeahh i'll try it now

forest osprey
forest osprey
#

bro is triggered by the guy with the kalashnikov bro, only csgo players get this mad

pearl raptor
#

it didn't work

#

it didn't work at all in fact, my character started flying

#

i only modified the rotation

#

okay nevermind i got it to work that way

pearl raptor
hallow sleet
#

local Control = script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule"):WaitForChild("MouseLockController")
Control:WaitForChild("BoundKeys").Value = "LeftControl"