Problem with forcing shiftlock

So, I’m making a shooter and I’ve found a force Shift Lock Script and I’ve found an issue:

I can peek through walls. I have no idea how to fix this.
code:

-- // Variables

-- # Services

local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local playersService = game:GetService("Players")
local TweenService = game:GetService("TweenService")

-- # Objects

local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character.HumanoidRootPart
local humanoid = character.Humanoid

local camera = game.Workspace.CurrentCamera

-- // Functions

humanoid.CameraOffset = Vector3.new(3, 1, 0)
humanoid.AutoRotate = false

runService:BindToRenderStep("Shiftlock", Enum.RenderPriority.Character.Value, function()
	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative

	local cameraCFrame = camera.CFrame
	local lookVector = -cameraCFrame.LookVector
	local angle = math.atan2(lookVector.x, lookVector.z)

	--TweenService:Create()
	humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, angle, 0)
end)

This is because you’re setting the humanoid.CameraOffset which ignores geometry. To fix this you shouldn’t use the CameraOffset property and instead raycast towards the offset you want, with the hit position of the ray being the position of the camera.

How would I find that I want 3 on the x coordinate? Would be different depending on which direction you are looking?

You would use the rightvector of the humanoidrootpart CFrame. Using the rightvector would make it offset relatively so the direction you’re looking at should be irrelevant.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.