Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] Mouse's Target giving incorrect input?

Asked by
ozzyDrive 670 Moderation Voter
6 years ago
Edited 5 years ago

I've struggled with this issue for over a week now and my project has halted completely. The mouse object is giving a wrong object as its target whenever I click. I made this little video demonstrating the issue, alongside with the exact place in this video.

In my original project I have tried different ways to mimic the Target property, none of them has worked.

function mouse:getTarget(directory)
--  local ray = Ray.new(realCamera.CFrame.p,realMouse.Origin.lookVector * 2000)
--  local part = workspace:FindPartOnRay(ray)
--  drawRay(ray)
--  return part

--  local mouseRay = realMouse.UnitRay
--  local ray = Ray.new(mouseRay.Origin,mouseRay.Direction * 2000)
--  local part = workspace:FindPartOnRay(ray)
--  drawRay(ray)
--  return part

--  I guess I just gotta experiment: use WorldToViewportPoint on all clickable objects and check if the mouse is on it on the xy-plane, if multiple ones are found it gives the one with the shortest distance
--  directory = directory or workspace
--  
--  local closest,dis = nil,math.huge
--  local children = directory:GetChildren()
--  for n = 1,#children do
--      local child = children[n]
--      if child:IsA("BasePart") then
--          local viewportPoint,isVisible = realCamera:WorldToViewportPoint(child.CFrame.p)
--          if isVisible then -- else just ignore
--              local delta = Vector2.new(viewportPoint.X - realMouse.X, viewportPoint.Y - realMouse.Y).magnitude
--              if delta < dis then
--                  closest = child
--                  dis = delta
--              end
--          end
--      end
--  end
--  return closest
end

Where "mouse" is a custom class and realMouse the actual PlayerMouse object. The reason I cannot really use the Target property even if this issue didn't exist, is because its distance is too limited for my needs. I would be using the Ray solution but the mouse's Hit property is also giving incorrect results, which must be connected to the Target issue.

I believe the camera's Focus property is causing this all but I have no idea why. This is how I'm updating the camera, as well as setting the Focus property:

function camera:update()
    if self.subject then
        realCamera.CFrame = self.subject.CFrame * self.rotation * CFrame.new(0,0,self.distance)
        realCamera.Focus = realCamera.CFrame
    end
end

1 answer

Log in to vote
0
Answered by
ozzyDrive 670 Moderation Voter
6 years ago
Edited 6 years ago

Changing CameraType of the player's camera to Custom fixed this issue although the default CameraScript has been completely disabled and my rewrite doesn't take this property into account in any way. ROBLOX documentation tells me nothing about this behaviour.

Ad

Answer this question