Mouse is offset in 3D space?

What I display in this clip is how my mouse in 3D is consistently offset from where my actual mouse should be in 3D and gets worse the further I am from my character it seems?

Does anyone have any idea why this could be happening?
FYI: I have tried
Mouse.Hit
Mouse.Target
aswell

function Mouse:GetMouseTarget()
    local Character = LocalPlayer.Character

    if Character then
        local Params = RaycastParams.new()
        Params.FilterType = Enum.RaycastFilterType.Exclude
        Params.FilterDescendantsInstances = {Character, workspace.Debris}

        local Mouse = LocalPlayer:GetMouse()
        local MouseLocation = UserInputService:GetMouseLocation()
        local Cast = Workspace.CurrentCamera:ViewportPointToRay(Mouse.X, Mouse.Y)

        local Ray = Workspace:Raycast(Cast.Origin, Cast.Direction * 2^8, Params)

        local TestPart = Instance.new("Part", workspace.Debris)
        TestPart.Anchored = true
        TestPart.Position = Ray and Ray.Position or Vector3.zero
        TestPart.Size = Vector3.one/2

        Debris:AddItem(TestPart, 0.1)

        return (Ray and Ray.Instance)
    end
end
3 Likes

When you click, does the click happen at your mouse pointer or at the moving dot?

1 Like

wdym by this? The loop is tracking the current mouse position (at least what is converted within the function into a vector)

Try using ScreenPointToRay instead of ViewportPointToRay


it’s a tiny bit better?

Are you sure the code you provided is accurate to what you’re running? I tried reproducing what you have but I’m not getting the same results?

Do you think it could do with the camera system, maybe since due to the camera orientation the direction is inaccurate, if so do you know what I could do about it?

I’ve already tried (Vector3.new(Mouse.X, Mouse.Y) - workspace.CurrentCamera.CFrame.Position).Unit for the direction.

code I ran vvv

local function point()
	local mouse = localPlayer:GetMouse()
	local camera = workspace.CurrentCamera
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {localPlayer.Character, workspace.debrisFolder}
	raycastParams.IgnoreWater = true

    if localPlayer.Character then
		local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y)
		local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 2^8, raycastParams)

		if raycastResult then
			local testPart = Instance.new("Part")
			testPart.Parent = workspace.debrisFolder
			testPart.Anchored = true
			testPart.Position = raycastResult and raycastResult.Position or Vector3.zero
			testPart.Size = Vector3.one/2
			Debris:AddItem(testPart, 0.1)
		end
    end
end

Can you send the camera code?

1 Like
function Camera:Render(dt) --// Our camera loop per frame
    self:GetCharacter():andThen(function(Char)
        local HumanoidRootPart = Char.PrimaryPart

        self:SetFov(20)
        self.Values.Target = (self.Values.AuxTarget == "None" and HumanoidRootPart or self.Values.AuxTarget.PrimaryPart)
        self.Camera.CameraSubject = self.Values.Target

        if self.Values.Zoomed == true then
            self.Values.CameraDepth = 0.4;
        else
            self.Values.CameraDepth = 0.7;
        end

        local CameraPosition = self.Values.Target.Position + Vector3.new(0, self.Values.HeightOffset)
        local Magnitude = (self.Values.Target.Position - self:GetCFrame().Position).Magnitude

        local X, Y = math.cos(self.CameraXDeg), math.sin(self.CameraXDeg)
        

        self.Values.CameraPositionSpring.Target = CameraPosition + Vector3.new(
            Magnitude * self.Values.CameraDepth * X,
            math.clamp((Magnitude*2) ^ 2 / 360 - 10, 35, 150) - self.CameraYDeg,
            Magnitude * self.Values.CameraDepth * Y
        )
        self.Values.FinalTargetSpring.Target = CameraPosition

        self:SetCFrame(
            CFrame.lookAt(
                self.Values.CameraPositionSpring.Position,
                self.Values.FinalTargetSpring.Position
            )
        )
    end)
end 

function Camera:KnitStart()
    for i, _ in pairs(self.Controllers) do
        self.Controllers[i] = Knit.GetController(i)
    end

    local Spring = self.Controllers["External"]:Load("Spring")
    self.Values.CameraPositionSpring = Spring.new(Vector3.new(0,0,0))
    self.Values.CameraPositionSpring.Target = self:GetCFrame().Position
    self.Values.CameraPositionSpring.Position = Vector3.new(0,0,0)
    self.Values.CameraPositionSpring.Velocity = Vector3.new(0,0,0)
    self.Values.CameraPositionSpring.Speed = 10

    self.Values.FinalTargetSpring = Spring.new(Vector3.new(0,0,0))
    self.Values.FinalTargetSpring.Target = Vector3.new(0,0,0)
    self.Values.FinalTargetSpring.Position = Vector3.new(0,0,0)
    self.Values.FinalTargetSpring.Velocity = Vector3.new(0,0,0)
    self.Values.FinalTargetSpring.Speed = 20
    self.Values.FinalTargetSpring.Damper = 0.8

    self.UIS.InputChanged:Connect(function(Input)
        if Input.UserInputType == Enum.UserInputType.MouseMovement then
            local Diff = Input.Delta.X * 0.001
            local DiffY = Input.Delta.Y * 0.1

            self.CameraYDeg = math.clamp(self.CameraYDeg - DiffY, -30, 30)
            self.CameraXDeg += Diff
        end
    end)

    self.UIS.InputEnded:Connect(function(Input, IsTyping)
        if IsTyping then return end

        if Input.UserInputType == Enum.UserInputType.MouseButton2 then
            self.CameraYDeg = 0
        end
    end)

    warn("Loaded camera spring.")
end ```

I’m thinking it has something to do with the field of view distorting something. Perhaps you could try to do something with the field of view and where the players mouse is?


Issue still seems to exist at the default fov.

1 Like

Are you sure you’re not doing something else? That code does works so maybe you’re casting from the character or something?

Fixed it, seemed the raycast distance was too low even though it seemed to be hitting the terrain just fine :rofl: , thanks for the help anyways.

1 Like

Ah!! seemingly not, I had it working and then after rerunning the game it stopped working


(no code was changed)

1 Like

but in that video it’s working?

thats what’s so confusing!!!

I don’t know what I did and why it worked

But if it’s working now, what’s the issue?

It’s not working no more, i’m unable to replicate it

I haven’t even changed the code from when it worked

Once again, I had it working but just to make sure I wasn’t bluffing, I stopped and played the game again and it once again reverted to not working