
u/Purple-Disk-5747

I'm working on a roblox game and I want to add tilting when ever I move forwards, sideways and backwards, similar to jujutsu shenanigans. Thank you in advance.
local cam = workspace.CurrentCamera
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local isActive = false
local cleanupFunction = nil
-- Create custom cursor GUI
local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local cursorGui = Instance.new("ScreenGui")
cursorGui.Name = "ShiftLockCursor"
cursorGui.IgnoreGuiInset = true
cursorGui.ResetOnSpawn = true
local cursorImage = Instance.new("ImageLabel")
cursorImage.Name = "Cursor"
cursorImage.Size = UDim2.new(0, 24, 0, 24)
cursorImage.Position = UDim2.new(0, 0, 0, 0) -- Will be updated to mouse position
cursorImage.AnchorPoint = Vector2.new(0.5, 0.5)
cursorImage.BackgroundTransparency = 1
cursorImage.Image = "rbxassetid://111927568272383"
cursorImage.Parent = cursorGui
cursorGui.Parent = playerGui
cursorGui.Enabled = false
local function customShiftLock()
`cam.CameraType = Enum.CameraType.Custom`
`humanoid.CameraOffset = Vector3.new(2, 2.5, 0)`
`UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter`
`UserInputService.MouseIconEnabled = false -- Hide default cursor completely`
`cursorGui.Enabled = true -- Show custom cursor`
`-- Make character face camera direction and update cursor to mouse position`
`local connection = RunService.RenderStepped:Connect(function()`
`-- Update cursor position to mouse location`
`local mouseLocation = UserInputService:GetMouseLocation()`
`cursorImage.Position = UDim2.new(0, mouseLocation.X, 0, mouseLocation.Y)`
`local hrp = character:FindFirstChild("HumanoidRootPart")`
`if hrp then`
`local lookDirection = cam.CFrame.LookVector`
`-- Ignore Y axis to keep character upright`
`local flatLook = Vector3.new(lookDirection.X, 0, lookDirection.Z)`
`if flatLook.Magnitude > 0 then`
hrp.CFrame = CFrame.new(hrp.Position, hrp.Position + flatLook)
`end`
`end`
`end)`
`return function ()`
`connection:Disconnect()`
`humanoid.CameraOffset = Vector3.new(0, 0, 0)`
`UserInputService.MouseBehavior = Enum.MouseBehavior.Default`
`UserInputService.MouseIconEnabled = true -- Restore default cursor`
`cursorGui.Enabled = false -- Hide custom cursor`
`end`
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
`if gameProcessed then return end`
`if input.KeyCode == Enum.KeyCode.LeftShift then`
`if isActive then`
`-- Deactivate shift lock`
`if cleanupFunction then`
cleanupFunction()
cleanupFunction = nil
`end`
`isActive = false`
`else`
`-- Activate shift lock`
`cleanupFunction = customShiftLock()`
`isActive = true`
`end`
`end`
end)
if humanoid.Health > 1 then
`cleanupFunction = nil`
end