ViewportPointToRay is offset with camera cframe being offset

for some reason, my raycast is still coming from the origin with ViewportPointToRay with custom shiftlock

ViewportPointToRay code

return function(ignore)
	local mouseLocation = input:GetMouseLocation()
	ignore = ignore or {}
	params.FilterDescendantsInstances = ignore

	local pointedRay = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
	local hitRaycast = workspace:Raycast(pointedRay.Origin, pointedRay.Direction * 250, params)
	
	return hitRaycast and hitRaycast.Instance.Parent
end

camera offset/shiftlock code

if self.ShiftlockEnabled and camera.CameraType ~= Enum.CameraType.Scriptable then
		local humanoid = player.Character.Humanoid
		local humanoidRootPart = player.Character.HumanoidRootPart

		if player:DistanceFromCharacter(camera.CFrame.Position) > 1 then
			camera.CFrame *= CFrame.new(1.75, 0.2, 0)
			input.MouseBehavior = Enum.MouseBehavior.LockCenter
			humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, camera.CFrame.LookVector * self.CameraOffset)
			humanoid.AutoRotate = false
		else
			humanoid.AutoRotate = true
		end
	end

for some reason it seems to only be affected in r6 i believe, which is annoying because my game is designed for r6.

1 Like

Hello, sorry for the late reply. I don’t really understand what you do you mean by ‘origin’, is that world origin (Vector3.new(0, 0, 0))?

1 Like

origin is referring to the ViewportToRay ray’s origin. it is the camera’s cframe before the multiplication happens in the 2nd code block

1 Like

hate to be that guy but can you record what it looks like and/or include more code
this is like very hard to work with icl

its fixed now i had to just work around with weird studio jank by setting it into a value instead of a variable

1 Like

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